Niko Grid Hooks
useDataGrid, useGridColumns, useGridChanges, and the internal grid hooks.
Use useDataGrid for the grid engine. Use useGridChanges to track edits for saving. It is a separate install. All hooks live in grid/hooks/.
useDataGrid
Section titled “useDataGrid”The headless engine. It holds rows, focus, selection, editing, and undo/redo. It has no domain logic.
import { useDataGrid } from "@/components/niko-table/grid/hooks/use-data-grid"
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.
Config
Section titled “Config”| Name | Type | Default | Description |
|---|---|---|---|
columnIds |
readonly string[] |
- | Editable column ids in visual order |
createEmptyRow |
(id: string) => TRow |
- | Factory for blank rows |
initialRows |
TRow[] |
- | Seed with exact rows |
initialRowCount |
number |
5 |
Blank seed count when no initialRows |
maxRows |
number |
200 |
Hard cap |
makeId |
() => string |
UUID | Runtime inserts only |
Return values (high level)
Section titled “Return values (high level)”| 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.
useGridColumns
Section titled “useGridColumns”Manages column specs at runtime for Dynamic Columns.
import { useGridColumns } from "@/components/niko-table/grid/hooks/use-grid-columns"
const cols = useGridColumns({ initialColumns })useGridChanges
Section titled “useGridChanges”Separate install: @niko-table/data-table-grid-changes. It reads grid.lastCommit.
const changes = useGridChanges(grid, { initialRows })changes.isDirtychanges.getChangeSet() // { created, updated, deleted }changes.reconcile({ succeededIds, failedIds })Internal hooks
Section titled “Internal hooks”Core and feature components use these. You rarely import them in app code.
| Hook | Role |
|---|---|
useGridKeyboard |
Scoped keydown state machine |
useGridNavigation |
Arrow / Tab / Home / End movement |
parseTsv / serializeSelection |
TSV parse / serialize helpers (plain functions, use-grid-clipboard.ts) |
useDataGridContext |
Context (lives in core). Throws outside the provider |