Documentation
Concepts

Loading data

Three ways to give the grid its rows, all rows at once, page by page as the end nears, or only the window in view.

The grid never fetches: it tells you what is in view, and you decide what to load and how to keep it. Fetching, caching and placeholders are your app's.

All the rows

Pass rows, an array. Append to it (a new array) and the grid renders the new rows, keeping the scroll position.

Sorting, filtering, searching and paging the rows you hold take one hook: Rows in memory. Selecting them is yours: the companies example sorts through the hook, and selects and deletes its own way.

Page by page

onRowsEndReached fires when the view's last row comes within endReachedThreshold rows of the end (10 by default), once per row count. Load the next page there and append it.

Infinite loading
Gallery

Only the window

For a dataset you cannot load in full, pass rowCount and getRow(index). The scrollbar represents every row from the start; getRow answers the row, or undefined while it is not loaded. A row not loaded keeps its place and renders with data-loading, so you can draw a placeholder.

Load what onRowWindowChange reports. When rows arrive, tell the grid which with rows.changed, through a gridRef: getRow stays the same function, and the grid renders again only when the rows that arrived are on screen. Rows that land far from the view cost nothing.

windowed.tsx
const gridRef = useDataGridRef<Person>();
// the cache tells which rows each block brought
useEffect(
    () =>
        cache.subscribe((range) =>
            gridRef.current?.model.run("rows.changed", range),
        ),
    [cache, gridRef],
);

<DataGrid.Root
    rowCount={1_000_000}
    getRow={cache.get}
    gridRef={gridRef}
    onRowWindowChange={({ rendered }) => cache.ensure(rendered.start, rendered.end)}
    …
/>

rows.changed takes { start, end } (end excluded), either bound alone, or nothing for every row. Passing a new getRow still works too, and renders the grid each time.

The same call serves data that changes all the time, as a live feed does: batch the moves and tell the grid their range once a frame. It renders the rows on screen again, once a frame whatever the rate, and nothing for the rows that moved out of view. The live-market example ticks a thousand rows up to ten thousand times a second that way, its summary row following with summary-rows.changed.

Wait for the scroll to settle before loading (a short timeout): a thumb dragged across the dataset then asks only for where it stops. See the windowed-loading example, and windowed-columns for the same with columns, by tiles.