Typed grid column definitions
experimental
Edit column definitions. A valueGetter takes precedence over field lookup in TypeScript.
Live example
Expected behavior
A valid configuration updates the table. Invalid changes show a path and preserve the last valid table.
Source
import { createGrid, type ColumnDef } from '@warlockcode/warui-core';
type Order = { id: string; price: number };
const columns: ColumnDef<Order>[] = [
{ id: 'order', field: 'id' },
{ id: 'display-price', field: 'price', valueGetter: row => row.price.toFixed(2) },
];
const grid = createGrid({ rows: [{ id: 'W-100', price: 4 }], columns, strict: true });
import { createGrid, type ColumnDef } from '@warlockcode/warui-core';
type Order = { id: string; price: number };
const columns: ColumnDef<Order>[] = [
{ id: 'order', field: 'id' },
{ id: 'display-price', field: 'price', valueGetter: row => row.price.toFixed(2) },
];
const grid = createGrid({ rows: [{ id: 'W-100', price: 4 }], columns, strict: true });
import { createGrid, type ColumnDef } from '@warlockcode/warui-core';
type Order = { id: string; price: number };
const columns: ColumnDef<Order>[] = [
{ id: 'order', field: 'id' },
{ id: 'display-price', field: 'price', valueGetter: row => row.price.toFixed(2) },
];
const grid = createGrid({ rows: [{ id: 'W-100', price: 4 }], columns, strict: true });
import { createGrid, type ColumnDef } from '@warlockcode/warui-core';
type Order = { id: string; price: number };
const columns: ColumnDef<Order>[] = [
{ id: 'order', field: 'id' },
{ id: 'display-price', field: 'price', valueGetter: row => row.price.toFixed(2) },
];
const grid = createGrid({ rows: [{ id: 'W-100', price: 4 }], columns, strict: true });
// JavaScript module for Blazor interop
import { createGrid, type ColumnDef } from '@warlockcode/warui-core';
type Order = { id: string; price: number };
const columns: ColumnDef<Order>[] = [
{ id: 'order', field: 'id' },
{ id: 'display-price', field: 'price', valueGetter: row => row.price.toFixed(2) },
];
const grid = createGrid({ rows: [{ id: 'W-100', price: 4 }], columns, strict: true });
API reference
| Kind | Name | Type | Description |
|---|---|---|---|
| Type | GridOptions<TRow> | — | Accepts typed rows, column definitions and a strict validation flag. |
| Type | ColumnDef<TRow> | — | Requires a unique id and accepts a field or a valueGetter. |
| Field | field | Extract<keyof TRow, string> | Reads a top-level field when no getter is supplied. |
| Field | valueGetter | (row: TRow) => unknown | Overrides field lookup and can compute a nested value. |
| Method | getColumns | () => readonly ColumnDef<TRow>[] | Returns immutable column definitions. |
| Error | GridConfigError | — | Includes a path for an invalid configuration. |