Niko Grid API Reference
Every Niko Grid hook, component, and cell editor on one page.
This page lists everything in one place. For a walkthrough, start with the Introduction. The pages below follow the source tree:
| Layer | Doc |
|---|---|
| Components | Overview |
| Core | Overview |
| Filters | Overview (via Niko Table) |
| Hooks | Overview |
| Library | Overview |
| Types | Overview |
| Config | Overview |
useDataGrid
Section titled “useDataGrid”The headless engine. It holds rows, focus, selection, editing, and undo/redo. It has no domain logic.
const grid = useDataGrid<TRow extends GridRow>({ columnIds, // editable column ids (visual order) createEmptyRow, // (id) => TRow initialRows, // seed data (optional) initialRowCount, // blank seed count when no initialRows (default 5) maxRows, // hard cap (default 200) makeId, // runtime inserts only (default crypto.randomUUID)})- Blank seeds from
initialRowCountget fixed ids likerow-0(safe for SSR). - Runtime
addRows,insertRows, andclearAllusemakeId.
| Field | Purpose |
|---|---|
rows |
Pass to DataTableRoot data |
lastCommit |
Last change signal. See Persistence |
focusedCell / editingCell / selectionAnchor |
Cursor + range by { rowId, columnId } |
selectCell / deselect / extendSelectionTo |
Move, clear, or extend selection (all leave edit mode) |
startEditing / stopEditing |
Open / close the editor |
setCell(rowId, colId, next) |
O(1) commit: one row identity changes |
updateRows / addRows / insertRows / removeRow / removeRows / clearAll |
Row mutations (undoable) |
undo / redo / canUndo / canRedo |
History |
updateRows(fn, { history: false })updates derived state (like cross-field validation) without adding an undo step. See Validation.clearAllreplaces every row with a blank one. The count matchesinitialRows.lengthorinitialRowCount.- Whole-row select, whole-column select, and
fillSelectionWithlive on the<DataGrid>context, not on this hook.
<DataGrid> / <DataGridCell>
Section titled “<DataGrid> / <DataGridCell>”<DataGrid grid={grid}>: put it insideDataTableRoot, wrappingDataTable.- It handles keyboard nav, the selection rectangle, drag-select, and scroll-into-view.
- Pass
onRequestShortcutsto open the?dialog.
<DataGridCell row columnId>: wrap each columncell.- It finds the display index from the row id, after sort and filter.
- Do not pass TanStack
row.index.
cell: (ctx) => ( <DataGridCell row={ctx.row.original} columnId={col.id}> {(p) => <GridTextCell {...p} resolve={(raw) => resolveCell(col.id, raw)} />} </DataGridCell>)Context helpers (via useDataGridContext): selectRow, selectColumn, fillSelectionWith, displayIndexOf, …
Cell editors
Section titled “Cell editors”Every visible cell shows a light display shell. The heavy editor mounts only while you edit.
| Component | Use |
|---|---|
GridTextCell |
Free text |
GridNumberCell |
Numeric; optional format for currency display |
GridCheckboxCell |
Boolean; always interactive |
GridDateCell |
Calendar; stores YYYY-MM-DD |
GridSelectCell |
Dropdown (no search) |
GridComboboxCell |
Searchable dropdown |
GridCellDisplay |
Shared read-only shell for custom cells |
Features
Section titled “Features”Add these as children of <DataGrid>. Anything you do not mount is tree-shaken.
| Component | Capability |
|---|---|
DataGridClipboard |
Copy / cut / paste (resolveCell is only needed for paste) |
DataGridFillHandle |
Corner fill; double-click auto-fill |
DataGridMove |
Drag block to move (Ctrl/Cmd = copy) |
DataGridRowReorder |
Row drag: prefer without active sort |
DataGridCrossHighlight |
Selection chrome on header / gutter |
DataGridStatusBar |
Aggregate the selection |
Dynamic columns
Section titled “Dynamic columns”useGridColumns({ initialColumns }) + <DataGridColumns value={cols}> + <GridColumnMenuOptions /> + <DataGridAddColumnButton />. See Dynamic Columns.
Toolbar
Section titled “Toolbar”From grid-toolbar: DataGridToolbar, DataGridUndo, DataGridRedo, DataGridAddRows, DataGridClearAll, DataGridPasteHint. For shortcuts, use DataGridShortcutsButton.
<DataGridAddRows count={5} /><DataGridAddRows count={1} className="w-full justify-center border-dashed" />Row menu
Section titled “Row menu”Put <GridRowMenu /> inside <DataTableRowContextMenuSlot>. It offers Copy, Cut, Clear, Delete, and Insert. Clipboard items show only when DataGridClipboard is mounted.
Persistence: useGridChanges
Section titled “Persistence: useGridChanges”Separate install: @niko-table/data-table-grid-changes.
const changes = useGridChanges(grid, { initialRows })changes.isDirtychanges.getChangeSet() // { created, updated, deleted }changes.reconcile({ succeededIds, failedIds })It reads grid.lastCommit. seq goes up only on real commits. See Persistence.
Core deps
Section titled “Core deps”Installing data-table-grid also adds scrollRowIntoView, flash helpers, toggleRowSelection, and column resize.