import { Component } from '@angular/core';
@Component({
selector: 'virtual-scroll-demo',
template: `
Virtual Scrolling with 10k Rows
Source
{{value}}
and {{value}}
`
})
export class VirtualScrollComponent {
rows = [];
expanded = {};
timeout: any;
constructor() {
this.fetch((data) => {
this.rows = data;
});
}
onPage(event) {
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
console.log('paged!', event);
}, 100);
}
fetch(cb) {
const req = new XMLHttpRequest();
req.open('GET', `assets/data/100k.json`);
req.onload = () => {
const rows = JSON.parse(req.response);
for(const row of rows) {
row.height = Math.floor(Math.random() * 80) + 50;
}
cb(rows);
};
req.send();
}
getRowHeight(row) {
return row.height;
}
}