Skip to content

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 };
    },
  },
});
OptionDefaultWhat it does
rowModel'client''infinite' selects this row model
serverRows.load(req)requiredFetch one block and answer { rows, totalRows? }; end is exclusive
serverRows.blockSize100Lines per block (10-1000)
serverRows.keepBlocks10Blocks to keep (2-100); beyond that the oldest hidden blocks are dropped
serverRows.initialRowCount50Placeholder 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 (signal is aborted).
  • The line count is the server's totalRows when 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 error event (serverRows.load) fires. Click the error line or press Enter to retry.
Method or eventWhat 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 ​

  • rowKey is required, and keys must be stable on the server.
  • It cannot be combined with pagination, tree, grouping, pinnedRows, detail, fullWidthRow or externalFilter. Row height is uniform, so rowHeight cannot be a function. Sorting is done by the server (sortMode: 'server' is switched on automatically). A violation throws invalid-option naming serverRows and 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 ArrowDown is not supported (it can be focused after it arrives).