LyteNyte Grid logo for light mode. Links back to the documentation home page.
Infinite Data Loading

Infinite Rows

Use the server data source to implement infinite scrolling and fetch rows as the user scrolls toward the bottom of the grid viewport.

Note

Infinite row loading uses the server data source. This guide assumes you’re familiar with the concepts covered in the Server Row Overview guide.

Infinite Row Loading

Infinite row loading detects when a user scrolls near the end of the viewport. Once the scroll position reaches a defined threshold, the grid requests the next data slice.

The example below uses the grid’s events property to register a scrollEnd listener. The listener checks whether the scroll position is within 100px of the total scroll height.

<Grid
events={useMemo<Grid.Events<GridSpec>>(() => {
return {
viewport: {
scrollEnd: ({ viewport }) => {
const top = viewport.scrollTop;
const left = viewport.scrollHeight - viewport.clientHeight - top;
if (left < 100) {
const req = ds.requestsForView.get().at(-1)!;
const next = { ...req, start: req.end, end: req.end + 100 };
ds.pushRequests([next]);
}
},
},
};
}, [ds])}
/>

This example shows one approach to implementing infinite row loading. The key implementation detail is creating a request for the next data slice and calling ds.pushRequests to fetch it. For more details, see the Data Interface guide.

The demo below demonstrates infinite data loading using this approach. When you scroll near the end of the grid, the grid loads additional rows after a brief delay.

Infinite Scrolling

Fork code on stack blitzFork code on code sandbox

Next Steps