Value Pipeline
Every cell edit, clipboard paste, drag-fill, and applyCellChanges call executes through a deterministic five-stage pipeline:
isEditable(params)— checks editability for(rowId, sourceIndex, dataEpoch, origin).valueParser(params)— converts editor text or pasted strings into domain values.valueValidator(params)— returnsnullwhen valid, or an error message string.valueEquals(params)— skips no-op writes (Object.isby default).valueSetter(params)— returns a new immutable rowTwith derived fields updated if needed.
import { Grid, type ColumnDef } from 'next-grid-js';import { createOrders, type OrderRow } from './data/orders';import { syncGridTheme } from './theme';import type { DemoMountContext } from './types';
export function mount({ stage, meta }: DemoMountContext): () => void { const columnDefs: readonly ColumnDef<OrderRow>[] = [ { key: 'id', name: 'ID', width: 96, }, { key: 'customer', name: 'Customer', width: 170, flex: 1, }, { key: 'quantity', name: 'Qty (1–100)', width: 115, cellDataType: 'number', isEditable: true, valueParser: ({ newValue }) => Number(newValue), valueValidator: ({ newValue }) => { const n = Number(newValue); if (!Number.isInteger(n) || n < 1 || n > 100) return 'Enter an integer from 1 to 100'; return null; }, valueSetter: ({ data, newValue }) => { const quantity = Number(newValue); return { ...data, quantity, amount: quantity * data.price, }; }, }, { key: 'amount', name: 'Amount (Auto)', width: 125, cellDataType: 'number', formatter: ({ value }) => `$${Number(value).toLocaleString('en-US')}`, }, ];
const grid = new Grid<OrderRow>({ container: stage, columnDefs, rowData: createOrders(20), getRowId: (row) => row.id, }); const stopTheme = syncGridTheme(stage);
grid.addEventListener('cellValuesChanged', ({ changes }) => { const c = changes[0]; if (c) meta.textContent = `Committed ${c.rowId}.${c.colId} = ${String(c.newValue)}`; }); grid.addEventListener('editSessionChanged', ({ session }) => { if (session?.validationMessage) meta.textContent = `Invalid: ${session.validationMessage}`; }); meta.textContent = 'Edit Qty (valid 1–100) to recompute Amount';
return () => { grid.destroy(); stopTheme(); };}Programmatic Mutations (applyCellChanges)
Section titled “Programmatic Mutations (applyCellChanges)”const result = grid.applyCellChanges( [{ cell: { row: { displayIndex: 0 }, colId: 'quantity' }, newValue: 12 }], { origin: 'api' },);- Return statuses (
CellMutationResult):{ status: 'applied' | 'requested' | 'unchanged', changes }{ status: 'invalid' | 'readonly' | 'unavailable', index, message }{ status: 'stale' }whendataEpochormodelVersionchanged before commit.
- Emits
cellValuesChangedon client arrays (orcellEditRequeston remote/rowSourcemodels).