Infinite scroll server rows
When there are too many rows to fetch at once, the grid fetches them in blocks as you scroll. It looks like one long list without pages, and lines not yet received show as a skeleton. Unlike pagination.mode: 'server' there are no page numbers, and the server handles sorting and filtering.
ts
createGrid(el, {
columns,
rowKey: 'id',
rowModel: 'infinite',
saveMode: 'none',
serverRows: {
async load({ start, end, sort, filter, quickFilter, signal }) {
const res = await fetch(`/api/rows?from=${start}&to=${end}`, { signal });
const { rows, total } = await res.json();
return { rows, totalRows: total };
},
},
});| Option | Default | What it does |
|---|---|---|
rowModel | 'client' | 'infinite' selects this row model |
serverRows.load(req) | required | Fetch one block and answer { rows, totalRows? }; end is exclusive |
serverRows.blockSize | 100 | Lines per block (10-1000) |
serverRows.keepBlocks | 10 | Blocks to keep (2-100); beyond that the oldest hidden blocks are dropped |
serverRows.initialRowCount | 50 | Placeholder lines at first, while the total is unknown |
The request (req) has start, end, the sort model sort, the column filter filter, the quick filter quickFilter and a cancel signal. The server is expected to apply sorting and filtering.
Behavior
- Blocks for lines entering the viewport are requested, at most two at a time. Responses for blocks you scrolled past, or sent before a sort or filter change, are dropped (
signalis aborted). - The line count is the server's
totalRowswhen given; otherwise it is the loaded end plus one block. A last block that is not full marks the end.setServerRowCount(n)sets it by hand. - Changing the sort, filter or quick filter cancels requests, clears the cache and reloads from the first block.
- Lines not received are
mxg-row-loading(aria-busy) and take no part in selection, editing, focus or export. Selected keys and export cover received rows only (a full export is the app's job on the server). - A failed block becomes an error line and an
errorevent (serverRows.load) fires. Click the error line or press Enter to retry.
| Method or event | What it does |
|---|---|
setServerRowCount(count | null) | Set the total line count; null means unknown |
refreshServerRows({ purge? }) | Reload the visible blocks; with purge the cache is dropped first |
purgeServerRows() | Drop the cache and reload the visible blocks |
getServerBlockState() | List of { block, start, end, state }; state is loading, loaded or error |
Event blockLoaded | { block, start, end, state, count } when a block becomes loaded or error |
Limits
rowKeyis required, and keys must be stable on the server.- It cannot be combined with
pagination,tree,grouping,pinnedRows,detail,fullWidthRoworexternalFilter. Row height is uniform, sorowHeightcannot be a function. Sorting is done by the server (sortMode: 'server'is switched on automatically). A violation throwsinvalid-optionnamingserverRowsand the other option. - Editing, undo and change tracking are not used: set
saveMode: 'none'and have no editable columns. - Moving focus onto a line not yet received with
ArrowDownis not supported (it can be focused after it arrives).