Skip to content

Column Definitions

columnDefs defines the schema, data extraction, formatting, and capabilities of each leaf column.

Data & Computed Columns
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 }: DemoMountContext): () => void {
const columnDefs: readonly ColumnDef<OrderRow>[] = [
{
key: 'id',
name: 'ID',
width: 96,
pinned: 'start',
},
{
key: 'customer',
name: 'Customer',
width: 175,
flex: 1,
},
{
key: 'quantity',
name: 'Qty',
width: 78,
cellDataType: 'number',
},
{
key: 'price',
name: 'Unit Price',
width: 105,
cellDataType: 'number',
formatter: ({ value }) => `$${Number(value).toFixed(2)}`,
},
{
colId: 'lineTotal',
name: 'Computed Total',
width: 135,
cellDataType: 'number',
valueGetter: ({ data }) => data.quantity * data.price,
formatter: ({ value }) =>
`$${Number(value).toLocaleString('en-US')}`,
},
{
key: 'orderedAt',
name: 'Order Date',
width: 120,
cellDataType: 'date',
},
];
const grid = new Grid<OrderRow>({
container: stage,
defaultColDef: {
isSortable: true,
isResizable: true,
},
columnDefs,
rowData: createOrders(30),
getRowId: (row) => row.id,
});
const stopTheme = syncGridTheme(stage);
return () => {
grid.destroy();
stopTheme();
};
}
  • Data column (DataColumnDef<T>): Set key to a property of your row type T. colId defaults to key; provide an explicit colId if two columns read the same property.
  • Computed column (ComputedColumnDef<T>): Omit key, set a unique colId, and provide valueGetter: ({ data }) => ....

Properties in defaultColDef apply to every column unless overridden on that column’s ColumnDef<T>:

const grid = new Grid<Order>({
container,
defaultColDef: { isSortable: true, isResizable: true, minWidth: 80 },
columnDefs: [
{ key: 'id', name: 'ID', width: 96, isResizable: false },
{ key: 'customer', name: 'Customer', flex: 1 },
],
rowData,
});
cellDataType Sorting Filtering Built-in Editor Excel Export Cell Type
'auto' Infers type from values Text / type-aware Text or boolean <select> Typed string/number/boolean/date
'text' Locale/lexical string compare Text operators (contains, startsWith, …) <input type="text"> Inline string
'number' Numeric compare (NaN sorted deterministically) Comparable operators (equals, inRange, …) <input type="text" inputMode="decimal"> Numeric cell
'boolean' Boolean compare 'equals', 'blank', 'notBlank' <select> ('', 'True', 'False') Boolean cell
'date' Calendar-day UTC timestamp YYYY-MM-DD parsed as UTC midnight <input type="text"> Excel date cell
'dateTime' Millisecond timestamp ISO-8601 date-time with timezone or UTC <input type="text"> Excel date cell
  • Date values: 'date' filter operands require YYYY-MM-DD (validated as UTC calendar days), and 'dateTime' parses valid ISO timestamps. Formatting (formatter) renders as textContent and never parses HTML.
  • Initial visibility: Set isVisible: false on a column to include it in state and data models while hiding it from initial rendering.