Skip to content

Value Pipeline

Every cell edit, clipboard paste, drag-fill, and applyCellChanges call executes through a deterministic five-stage pipeline:

  1. isEditable(params) — checks editability for (rowId, sourceIndex, dataEpoch, origin).
  2. valueParser(params) — converts editor text or pasted strings into domain values.
  3. valueValidator(params) — returns null when valid, or an error message string.
  4. valueEquals(params) — skips no-op writes (Object.is by default).
  5. valueSetter(params) — returns a new immutable row T with derived fields updated if needed.
Validation & Derived Fields via valueSetter
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();
};
}
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' } when dataEpoch or modelVersion changed before commit.
  • Emits cellValuesChanged on client arrays (or cellEditRequest on remote/rowSource models).