Skip to content
Niko Table

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

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 initialRowCount get fixed ids like row-0 (safe for SSR).
  • Runtime addRows, insertRows, and clearAll use makeId.
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.
  • clearAll replaces every row with a blank one. The count matches initialRows.length or initialRowCount.
  • Whole-row select, whole-column select, and fillSelectionWith live on the <DataGrid> context, not on this hook.
  • <DataGrid grid={grid}>: put it inside DataTableRoot, wrapping DataTable.
    • It handles keyboard nav, the selection rectangle, drag-select, and scroll-into-view.
    • Pass onRequestShortcuts to open the ? dialog.
  • <DataGridCell row columnId>: wrap each column cell.
    • 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, …

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

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

useGridColumns({ initialColumns }) + <DataGridColumns value={cols}> + <GridColumnMenuOptions /> + <DataGridAddColumnButton />. See Dynamic Columns.

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" />

Put <GridRowMenu /> inside <DataTableRowContextMenuSlot>. It offers Copy, Cut, Clear, Delete, and Insert. Clipboard items show only when DataGridClipboard is mounted.

Separate install: @niko-table/data-table-grid-changes.

const changes = useGridChanges(grid, { initialRows })
changes.isDirty
changes.getChangeSet() // { created, updated, deleted }
changes.reconcile({ succeededIds, failedIds })

It reads grid.lastCommit. seq goes up only on real commits. See Persistence.

Installing data-table-grid also adds scrollRowIntoView, flash helpers, toggleRowSelection, and column resize.