Virtualization
NextGrid bounds allocated DOM nodes by the visible viewport size plus rowOverscan and columnOverscan, rather than dataset row or column counts.
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(); };}Core Virtualization Guarantees
Section titled “Core Virtualization Guarantees”- Row & Cell DOM Pools: Rows and cells are recycled in place as you scroll vertically or horizontally, keeping steady-state scroll free of DOM node creation.
- Column Virtualization (
columnOverscan): Grids with hundreds or thousands of columns virtualize horizontally so only visible columns pluscolumnOverscan(default2) mount cell DOM. - Single Native Scroll Owner:
.grid-body-viewportowns native vertical and horizontal scrollbars; pinned start/end regions and headers synchronize through oneSurfaceCoordinatorpass. - Overscan Tuning: Increase
rowOverscan(default3) orcolumnOverscan(default2) for fast wheel scrolling on tall rows, or lower them to minimize DOM footprint per frame.