REQUIREMENT:
I have a Kendo grid which displays tabular data. Initially the grid would fetch certain number of rows and upon reaching scroll end, it should make a http call to get more rows appending to the existing list. Earlier achieved this using Kendo ui jquery.
SCROLL:
Am not sure if this is a native scroll event to Kendo grid for angular. So am attaching a scroll event myself to DOM. When scroll reaches end, I make a call ,
append more data and pass griddata to ui.
WITH VIRTUAL SCROLL:
From what I understand, whole data is retrieved before hand and using skip, pagenumber, we display what we need. What I need is more of an endless scroll which appends to previous data.
CODE:
ngAfterViewInit() { // attaches scroll event
let scrolldiv = document.getElementsByClassName("k-grid-content")[0];
if (scrolldiv) {
scrolldiv.addEventListener("scroll", this.addMoreData.bind(this));}
}
addMoreData(event) { // adds more data and passed grid data.
let scrollAdjustment = 10;
if (event.target.scrollTop != 0 && event.target.clientHeight + event.target.scrollTop + scrollAdjustment >= event.target.scrollHeight) {
let moreRows = this.getMoreRows();
this.gridView = {
data: moreRows,
total: moreRows.length
}
} }
kendo template::
<kendo-grid [data]="gridView" class="customgrid" >
<div *ngFor="let col of totalColumns; ">
<kendo-grid-column field="{{col.label}}" title="{{col.label}}" width="120"></kendo-grid-column>
</div>
<kendo-grid>
1. Is there a better way in Kendo UI Angualr to achieve this. The event I attach is defined only if there is a scrollable div inside kendo grid (which is only if there are enough columns to bring a scrollbar)
2. In case of Ng for, dynamically repeating , may I know how to access the data passed to <kendo-grid [data] > from ng for loop. Right now in NGFOR am accessing field values using a different variable (not [data]="gridView")