|
[app.component.ts]
export class AppComponent {
@ViewChild("grid")
public grid: GridComponent;
public data;
ngOnInit(): void {
this.data = new DataManager({
adaptor: new ODataV4Adaptor()
});
}
makeRequest(args) {
var infiniterequestrow = this.grid.element.querySelector(
".infiniterequestrow"
);
if (infiniterequestrow != undefined) {
var topvalue = (infiniterequestrow as HTMLElement).offsetTop;
// check if the last 20th row from bottom reaches the top
if (topvalue < (this.grid.scrollModule as any).previousValues.top) {
// executed if last 20th row reaches the top
this.grid.showSpinner();
// remove the custom CSS Class
infiniterequestrow.classList.remove("infiniterequestrow");
// make the parameters to request next block records
let rows: Element[] = this.grid.getRows();
let index: number =
parseInt(rows[rows.length - 1].getAttribute("aria-rowindex"), 10) + 1;
var prevPage = this.grid.pageSettings.currentPage;
if (this.grid.pageSettings.currentPage == 1) {
this.grid.pageSettings.currentPage = 4;
} else {
this.grid.pageSettings.currentPage = prevPage + 1;
}
args = {
requestType: "infiniteScroll",
currentPage: this.grid.pageSettings.currentPage,
prevPage: prevPage,
startIndex: index,
direction: "down"
};
// request the next block records by executing makeRequest method of Grid
(this.grid.infiniteScrollModule as any).makeRequest(args);
}
}
}
dataBound(args) {
// add the custom class to the 20th row from bottom
this.grid.getRows()[this.grid.getRows().length - 20].classList.add("infiniterequestrow");
// add the scroll event to the grid content
this.grid.element.querySelector(".e-content").addEventListener(
"scroll",
function(args) {
// call this function when scrolling the grid content
this.makeRequest(args);
}.bind(this)
);
}
actionBegin(args) {
console.log(args);
}
}
|
Hello Syncfusion community,
Similar to Ahmad, I've been working with the Infinite Scrolling feature in the Syncfusion Grid component for React. Currently, the InfiniteScrolling service makes the request to load the next set of elements only when the user reaches the bottom of the grid. However, I would like to enhance the user experience by triggering the service call when the user is about to reach the bottom, let's say 10 or 20 rows before.
I noticed a suggestion in a similar context, but I'm wondering if there is a more direct approach to achieve this in ReactJS.
Looking forward to your guidance.
Best regards, Santiago Muñoz B
Hi Santiago Muñoz,
Since the requested scenario is not our default behavior there is no direct approach for React Grid component. As we suggested earlier, we need to use the workaround inside the “dataBound” event. We have prepared a sample with the React Grid component. Please refer to the below link for more information.
https://stackblitz.com/edit/react-ndndz2-prsytp?file=index.js
Regards,
Pavithra S