Examples
Explore interactive NextGrid scenarios running live in your browser. Each demo loads lazily as you scroll.
1,000,000 Lazy Rows
Section titled “1,000,000 Lazy Rows”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(); };}Multi-Level Row Grouping & Totals
Section titled “Multi-Level Row Grouping & Totals”import { Grid } from 'next-grid-js';import { createSales, type SaleRow } from './data/sales';import { syncGridTheme } from './theme';import type { DemoMountContext } from './types';import { addButton } from './ui';
export function mount({ stage, controls, meta,}: DemoMountContext): () => void { const grid = new Grid<SaleRow>({ container: stage, columnDefs: [ { key: 'region', name: 'Region', width: 105, isSortable: true, }, { key: 'country', name: 'Country', width: 115, isSortable: true, }, { key: 'quarter', name: 'Quarter', width: 90, isSortable: true, }, { key: 'product', name: 'Product', width: 110, }, { key: 'units', name: 'Units', width: 85, cellDataType: 'number', }, { key: 'revenue', name: 'Revenue', width: 120, cellDataType: 'number', formatter: ({ value }) => `$${Number(value).toLocaleString('en-US')}`, }, ], rowData: createSales(), getRowId: (row) => row.id, rowGrouping: { columns: ['region', 'country'], autoColumn: { name: 'Territory', width: 200, pinned: 'start', }, }, valueColumns: [ { colId: 'units', aggFunc: 'sum', }, { colId: 'revenue', aggFunc: 'sum', }, ], groupTotals: true, grandTotal: true, defaultExpandedDepth: 1, aggregateFormatter: ({ value, colId }) => value === null ? '' : colId === 'revenue' ? `$${Number(value).toLocaleString('en-US')}` : String(value), }); const stopTheme = syncGridTheme(stage);
const updateMeta = () => { const counts = grid.getHierarchyCounts(); if (counts) meta.textContent = `Visible nodes: ${counts.visibleNodes} · Source rows: ${counts.sourceRows ?? 0}`; }; grid.addEventListener('hierarchyChanged', updateMeta); addButton(controls, 'Expand all', () => grid.expandAllGroups()); addButton(controls, 'Collapse all', () => grid.collapseAllGroups()); updateMeta();
return () => { grid.destroy(); stopTheme(); };}Client-Side Pivot Matrix
Section titled “Client-Side Pivot Matrix”import { Grid } from 'next-grid-js';import { createSales, type SaleRow } from './data/sales';import { syncGridTheme } from './theme';import type { DemoMountContext } from './types';import { addButton } from './ui';
export function mount({ stage, controls, meta,}: DemoMountContext): () => void { let pivotEnabled = true;
const pivotConfig = { rowGroupColumns: ['region', 'country'], pivotColumns: ['quarter'], measures: [ { measureId: 'revenue', colId: 'revenue', aggFunc: 'sum', }, ], rowTotals: true, columnTotals: true, };
const grid = new Grid<SaleRow>({ container: stage, columnDefs: [ { key: 'region', name: 'Region', width: 100, }, { key: 'country', name: 'Country', width: 110, }, { key: 'quarter', name: 'Quarter', width: 90, }, { key: 'revenue', name: 'Revenue', width: 115, cellDataType: 'number', }, ], rowData: createSales(), getRowId: (row) => row.id, pivot: pivotConfig, pivotGroupColumn: { name: 'Territory', width: 185, pinned: 'start', }, pivotValueFormatter: ({ value }) => value === null ? '—' : `$${Number(value).toLocaleString('en-US')}`, }); const stopTheme = syncGridTheme(stage);
const updateMeta = () => { const counts = grid.getPivotCounts(); meta.textContent = counts ? `Result rows: ${counts.visibleResultRows} · Result cols: ${counts.resultColumns}` : 'Source view'; }; grid.addEventListener('pivotChanged', updateMeta);
const toggleBtn = addButton(controls, 'Exit pivot', () => { pivotEnabled = !pivotEnabled; grid.setPivot(pivotEnabled ? pivotConfig : false); toggleBtn.textContent = pivotEnabled ? 'Exit pivot' : 'Enable pivot'; }); addButton(controls, 'Expand all', () => grid.expandAllGroups()); updateMeta();
return () => { grid.destroy(); stopTheme(); };}Master / Detail with Nested Grid
Section titled “Master / Detail with Nested Grid”import { Grid, type ColumnDef } from 'next-grid-js';import { createOrders, type OrderRow } from './data/orders';import { syncGridTheme } from './theme';import type { DemoMountContext } from './types';import { addButton } from './ui';
export function mount({ stage, controls, meta,}: DemoMountContext): () => void { const rows = createOrders(15);
const columnDefs: readonly ColumnDef<OrderRow>[] = [ { key: 'id', name: 'ID', width: 96, }, { key: 'customer', name: 'Customer', width: 175, flex: 1, }, { key: 'product', name: 'Product', width: 175, }, { key: 'amount', name: 'Amount', width: 115, cellDataType: 'number', formatter: ({ value }) => `$${Number(value).toLocaleString('en-US')}`, }, ];
const grid = new Grid<OrderRow>({ container: stage, columnDefs, rowData: rows, getRowId: (row) => row.id, detail: { isMaster: () => true, estimatedHeight: 132, renderer: ({ data, document: doc, registerChild }) => { const wrap = doc.createElement('div'); wrap.style.cssText = 'padding:8px 14px;height:132px;box-sizing:border-box'; const host = doc.createElement('div'); host.style.cssText = 'height:100%;width:100%'; wrap.append(host);
const child = new Grid({ container: host, ariaLabel: `Line items for ${data.id}`, columnDefs: [ { key: 'sku', name: 'Item', width: 180, flex: 1, }, { key: 'qty', name: 'Qty', width: 85, cellDataType: 'number', }, { key: 'unit', name: 'Unit Price', width: 110, cellDataType: 'number', }, ], rowData: [ { sku: data.product, qty: data.quantity, unit: data.price, }, { sku: 'Handling & SLA', qty: 1, unit: 25, }, ], getRowId: (r) => r.sku, }); registerChild(child);
return { element: wrap, destroy: () => wrap.remove(), }; }, }, }); const stopTheme = syncGridTheme(stage);
grid.setDetailExpanded({ rowId: rows[0].id }, true); grid.addEventListener('detailChanged', ({ detail }) => { meta.textContent = `Expanded details: ${detail.expanded.length}`; });
addButton(controls, 'Toggle first row', () => { const id = rows[0].id; const isOpen = grid .getDetailState() .expanded.some((a) => 'rowId' in a && a.rowId === id); grid.setDetailExpanded({ rowId: id }, !isOpen); }); meta.textContent = 'Expanded details: 1';
return () => { grid.destroy(); stopTheme(); };}Data Export & Body Context Menu
Section titled “Data Export & Body Context Menu”import { Grid } from 'next-grid-js/core';import { ExportModule } from 'next-grid-js/export';import { createOrders, type OrderRow } from './data/orders';import { syncGridTheme } from './theme';import type { DemoMountContext } from './types';import { addButton } from './ui';
export function mount({ stage, controls, meta,}: DemoMountContext): () => void { const grid = new Grid<OrderRow>({ container: stage, modules: [ExportModule], columnDefs: [ { key: 'id', name: 'ID', width: 96, 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', formatter: ({ value }) => `$${Number(value).toLocaleString('en-US')}`, }, { key: 'orderedAt', name: 'Order Date', width: 115, cellDataType: 'date', }, ], rowData: createOrders(35), getRowId: (row) => row.id, rowSelection: { mode: 'multiple', showCheckbox: true, }, dataExport: { formats: ['csv', 'xlsx', 'json', 'markdown'], fileName: ({ format }) => `orders-demo.${format}`, }, }); const stopTheme = syncGridTheme(stage);
addButton(controls, 'Preview CSV', async () => { const res = await grid.exportData({ format: 'csv', rows: 'filtered', }); meta.textContent = `CSV: ${res.rowCount} rows (${res.text.length} chars)`; }); addButton(controls, 'Preview JSON', async () => { const res = await grid.exportData({ format: 'json', rows: 'filtered', }); meta.textContent = `JSON: ${res.rowCount} rows (${res.text.length} chars)`; }); addButton(controls, 'Download XLSX', async () => { const res = await grid.downloadExport({ format: 'xlsx', rows: 'filtered', }); meta.textContent = `Downloaded ${res.fileName} (${res.bytes.byteLength} bytes)`; }); meta.textContent = 'Use footer Export or toolbar buttons';
return () => { grid.destroy(); stopTheme(); };}