Lazy RowSource
When your application generates rows mathematically, reads from typed arrays, or indexes a massive local buffer, RowSource<T> lets NextGrid query only the rows currently inside the viewport plus rowOverscan.
import { Grid, type ColumnDef, type GridRenderDiagnostics,} from 'next-grid-js';import { createMillionRowSource, type TelemetryRow,} from './data/telemetry';import { syncGridTheme } from './theme';import type { DemoMountContext } from './types';
export function mount({ stage, meta }: DemoMountContext): () => void { let lastFrameText = '';
const columnDefs: readonly ColumnDef<TelemetryRow>[] = [ { key: 'id', name: 'ID', width: 118, pinned: 'start', isMovable: false, }, { key: 'region', name: 'Region', width: 120, minWidth: 105, flex: 1, }, { key: 'uptime', name: 'Uptime', width: 110, minWidth: 95, flex: 1, cellDataType: 'number', formatter: ({ value }) => `${Number(value).toFixed(2)}%`, }, { key: 'latency', name: 'Latency', width: 110, minWidth: 95, flex: 1, cellDataType: 'number', formatter: ({ value }) => `${Number(value).toFixed(1)} ms`, }, { key: 'volume', name: 'Volume', width: 135, minWidth: 115, flex: 1.15, cellDataType: 'number', formatter: ({ value }) => `$${Number(value).toLocaleString('en-US')}`, }, { key: 'status', name: 'Status', width: 115, minWidth: 95, flex: 1, }, ];
const grid = new Grid<TelemetryRow>({ container: stage, columnDefs, rowSource: createMillionRowSource(1_000_000), rowOverscan: 6, columnOverscan: 2, diagnostics: { onFrame: (d: Readonly<GridRenderDiagnostics>) => { const text = `Rows: 1,000,000 · DOM rows: ${d.dom.activeRows} · ${d.renderDurationMs.toFixed(1)} ms`; if (text !== lastFrameText) { lastFrameText = text; meta.textContent = text; } }, }, }); const stopTheme = syncGridTheme(stage);
return () => { grid.destroy(); stopTheme(); };}Implementing RowSource<T>
Section titled “Implementing RowSource<T>”const source: RowSource<TelemetryRow> = { getRowCount: () => 1_000_000, getRow: (index) => (index >= 0 && index < 1_000_000 ? makeRow(index) : undefined), getRowId: (row) => row.id, // Optional fast reverse lookup: getRowIndexById: (rowId) => parseIndex(rowId),};
const grid = new Grid<TelemetryRow>({ container, columnDefs, rowSource: source,});Behavior & Constraints
Section titled “Behavior & Constraints”- Returning
undefined: IfgetRow(index)returnsundefined, the row renders as unavailable without crashing. - No Client Processing / Grouping / Pivot:
rowSourcedoes not run client-side sorting, filtering, grouping, or pivot; sort/filter your underlying source and callgrid.setRowSource(nextSource)orgrid.refreshRows(). - Controlled Editing: Editing a
rowSourcecell emitscellEditRequestrather than mutating the source directly.