Skip to content

Infinite Row Model

Use rowModelType: 'infinite' to scroll seamlessly across large remote datasets while NextGrid caches only the blocks near the active viewport.

Infinite Block-Cached Model
import { Grid, type ColumnDef } from 'next-grid-js';
import { createFakeRemoteDatasource } from './data/fake-server';
import type { OrderRow } from './data/orders';
import { syncGridTheme } from './theme';
import type { DemoMountContext } from './types';
export function mount({ stage, meta }: DemoMountContext): () => void {
const { datasource } = createFakeRemoteDatasource(180);
const columnDefs: readonly ColumnDef<OrderRow>[] = [
{
key: 'id',
name: 'ID',
width: 96,
pinned: 'start',
isSortable: true,
},
{
key: 'customer',
name: 'Customer',
width: 175,
flex: 1,
isSortable: true,
},
{
key: 'region',
name: 'Region',
width: 105,
isSortable: true,
},
{
key: 'amount',
name: 'Amount',
width: 115,
cellDataType: 'number',
isSortable: true,
formatter: ({ value }) =>
`$${Number(value).toLocaleString('en-US')}`,
},
{
key: 'status',
name: 'Status',
width: 105,
},
];
const grid = new Grid<OrderRow>({
container: stage,
columnDefs,
rowModelType: 'infinite',
datasource,
remoteOptions: {
blockSize: 25,
maxBlocks: 6,
prefetchBlocks: 1,
initialRowCount: {
kind: 'estimated',
count: 500,
},
},
getRowId: (row) => row.id,
});
const stopTheme = syncGridTheme(stage);
grid.addEventListener('datasourceChanged', ({ data }) => {
if (data.rowModelType !== 'viewport') {
meta.textContent = `Loaded: ${data.loadedRows}/${data.rowCount.count} · Pending: ${data.pendingRequests}`;
}
});
return () => {
grid.destroy();
stopTheme();
};
}
const grid = new Grid<OrderRow>({
container,
columnDefs,
rowModelType: 'infinite',
datasource,
remoteOptions: {
blockSize: 100, // default: 100 (max 10,000)
maxBlocks: 10, // default: 10 (max 1,000)
maxConcurrentRequests: 2,// default: 2 (max 32)
prefetchBlocks: 1, // default: 1 (max 1,000)
retryCount: 2, // default: 2 (max 10)
retryDelayMs: 100, // default: 100 (max 60,000)
initialRowCount: { kind: 'estimated', count: 1000 },
},
getRowId: (row) => row.id,
});

datasource.getRows(request) receives startRow, endRow, generation, requestId, signal (AbortSignal), sort, filters, and quickFilter, and returns { startRow, rows, rowCount }, where rowCount has kind: 'estimated' | 'known' | 'final'.

  • Sorting and filtering delegate to your backend (sort/filters/quickFilter in request).
  • Stale or aborted block responses are rejected automatically by generation tracking.