Skip to content
Niko Table

Niko Grid

An editable spreadsheet grid for React. You copy it into your project, like shadcn/ui.

grid-all-features.tsx
Stress test:
Paste a spreadsheet (Ctrl/Cmd+V) to fill rows
Current Table State
Live view of table + grid state for demonstration
Search Query:None
Total Rows:500
Selected Rows:0
Active Filters:0
Sorting:None
Hidden Columns:0
Pinned Columns:1 Left, 0 Right
Dynamic Columns:10
Focused Cell:None
Editing Cell:None
Selection Anchor:None
Can Undo / Redo:No / No
Last Commit:None

Keyboard nav, clipboard, fill, filters, dynamic columns, and typed editors. Each one is an opt-in child.

Use Niko Grid when you want a Niko Table that users can edit like a spreadsheet. It is part of Niko Table, not a separate library.

  • From the table: virtualization, sort, filter, pin, and resize.
  • From the grid: a headless edit engine for focus, selection, undo/redo, and clipboard.

Why it works well:

  • Composable: add only the features you need as children of <DataGrid>.
  • Id-addressed: focus and edits use the row id, so sort and filter stay correct.
  • Fast: cell commits are O(1), the body is virtualized, and unused features add no listeners.
  • Your code: you copy it in through the registry. Nothing is hidden.
  1. Add the registry under registries in components.json (merge with your existing config):

    components.json
    {
    "registries": {
    "@niko-table": "https://niko-table.com/r/{style}/{name}.json"
    }
    }
  2. Install the grid. This also adds data-table, virtualization, and column resize:

    pnpm dlx shadcn@latest add @niko-table/data-table-grid

To copy files by hand, see the Installation Guide.

The grid has two kinds of pieces:

  • Table chrome (useDataTable): search, faceted filters, sort, view, export, pagination.
    • Put it anywhere under DataTableRoot, beside <DataGrid> or inside it.
  • Grid pieces (useDataGridContext): undo/redo, add rows, clipboard, fill, move, reorder.
    • These must be children of <DataGrid>.
DataTableRoot ← data={grid.rows}
├─ Search / Faceted / Sort / Clear / View / … ← table chrome (Root is enough)
└─ DataGrid ← keyboard, selection, scroll-into-view
├─ DataGridToolbar (Undo, Add rows, …) ← grid chrome (needs DataGrid)
├─ DataGridClipboard / Fill / Move / Reorder ← grid opt-ins
└─ DataTable
├─ VirtualizedHeader
└─ VirtualizedBody
└─ DataGridCell → GridTextCell / …
Layer Where Role
useDataGrid Call site Headless engine: rows, focus, edit, undo/redo
Table chrome Under DataTableRoot Filters / sort / view / pagination
<DataGrid> Under DataTableRoot Display-order nav + selection
Grid chrome + opt-ins Inside <DataGrid> Undo, add rows, clipboard, fill, move, …
Cell editors Column cell render Display shell; heavy editor only while editing

The smallest useful grid has text cells, clipboard, and fill.

grid-basic.tsx
Paste a spreadsheet (Ctrl/Cmd+V) to fill rows
TaskAssigneeStatus
Preview with Controlled State
grid-basic-state.tsx
Paste a spreadsheet (Ctrl/Cmd+V) to fill rows
TaskAssigneeStatus
Current Grid State
Live view of the grid engine state for demonstration
Focused Cell:None
Editing Cell:None
Selection Anchor:None
Total Rows:3
Can Undo / Redo:No / No
Last Commit:None
  1. Create the engine

    const COLUMN_IDS = ["task", "assignee", "status"] as const
    const createEmptyRow = (id: string): GridRow => ({ id })
    const grid = useDataGrid<GridRow>({
    columnIds: COLUMN_IDS,
    createEmptyRow,
    initialRows,
    })
  2. Resolve raw text → CellState

    const resolveCell = (columnId: string, raw: string): CellState<string> => ({
    raw,
    value: raw || null,
    status: raw === "" ? "empty" : "valid",
    })
  3. Wire columns. accessorFn returns raw text, so sort, filter, and CSV export work. Wrap each cell in <DataGridCell>:

    const columns: DataTableColumnDef<GridRow>[] = COLUMN_IDS.map((id) => ({
    id,
    accessorFn: (row) => {
    const v = row[id]
    return typeof v === "object" && v != null ? v.raw : ""
    },
    header: id,
    cell: (ctx) => (
    <DataGridCell row={ctx.row.original} columnId={id}>
    {(p) => (
    <GridTextCell {...p} resolve={(raw) => resolveCell(id, raw)} />
    )}
    </DataGridCell>
    ),
    }))
  4. Compose

    <DataTableRoot data={grid.rows} columns={columns} getRowId={(r) => r.id}>
    <DataGrid grid={grid}>
    <DataGridClipboard resolveCell={resolveCell} />
    <DataGridFillHandle />
    <DataTable maxHeight={360}>
    <DataTableVirtualizedHeader />
    <DataTableVirtualizedBody estimateSize={37}>
    <DataTableRowContextMenuSlot>
    <GridRowMenu />
    </DataTableRowContextMenuSlot>
    </DataTableVirtualizedBody>
    </DataTable>
    </DataGrid>
    </DataTableRoot>

Add any of these inside <DataGrid>. If you do not mount one, it costs nothing.

Component Capability
DataGridClipboard Copy / cut / paste (quote-aware TSV)
DataGridFillHandle Corner-drag fill (Ctrl/Cmd+Enter fill-selection works grid-wide, no handle needed)
DataGridMove Drag selection border to move (Ctrl/Cmd to copy)
DataGridRowReorder Drag rows by grip (avoid combining with sort)
DataGridCrossHighlight Row / column chrome for the selection
DataGridStatusBar Count / Sum / Avg / Min / Max
DataTableColumnResize Drag resize; double-click to autosize
DataGridUndo / DataGridRedo History

Filters, sort, pin, and the view menu are regular Niko Table components. Put them under DataTableRoot, beside or inside <DataGrid>.

Do not put DataGridUndo, DataGridAddRows, or clipboard pieces outside <DataGrid>.

More detail by layer: Components, Core, Hooks. Everything in one page: API Reference.

  • Move and edit: Arrows, Tab, Enter, Escape. Type to start editing.
  • Select: Mod+A selects all. Mod+Arrow jumps to the edge.
  • Clear: Delete.
  • Clipboard: Mod+C, Mod+X, Mod+V.
  • History: Mod+Z to undo, Mod+Shift+Z to redo.
  • Help: DataGridShortcutsButton opens the cheat sheet.

useDataGrid owns the rows. They are uncontrolled, like defaultValue. Controlling every keystroke would rebuild the table model and break undo.

To save your data:

  • Save button: read grid.rows (or useGridChanges().getChangeSet()) on submit.
  • Autosave: debounce the network call, not the UI.

See Persistence.