Data Grid
Editable React data grid that works like a spreadsheet: arrow keys between cells, type to edit, block selection, copy and paste with Excel or Sheets, undo.
Installation
npx shadcn@latest add @minidev/data-grid
MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/data-grid.json
Usage
import { DataGrid } from "@/components/ui/data-grid"
export function Example() {
return (
<DataGrid />
)
}
API reference
| Prop | Type | Default |
|---|---|---|
| columnsrequiredColumn definitions, left to right. The first column stays visible while scrolling sideways. | DataGridColumn<T>[] | - |
| rowsrequiredThe rows to show. The grid never copies them: edits go to `onRowsChange`. | T[] | - |
| onRowsChangeFires with a new rows array after each edit, paste, clear or undo. Leave it out for a read-only grid. | (rows: T[]) => void | - |
| getRowIdStable key for each row. Defaults to the row index. | (row: T, index: number) => string | (_, i) => String(i) |
| rowNumbersShow a numbered column on the left. Click a number to select its row. | boolean | true |
| aria-labelrequiredAccessible name of the grid, such as "Price list". | string | - |
| classNameSize the scroll area here, for example `max-h-[32rem]`. | string | - |
When to use
Use it when people change many values in place: price lists, stock counts, budgets, bulk imports. Columns are text, number, select or checkbox. Shift+arrows select a block, Cmd/Ctrl+C copies it as tab-separated text, Cmd/Ctrl+V pastes a block from a spreadsheet and turns "1,240.50" into a number, Delete clears and Cmd/Ctrl+Z undoes. The grid is controlled: it shows rows and hands every edit to onRowsChange; without that prop it is read-only. The header and first column stay put while you scroll, and columns resize by dragging the header edge. For sorting, filtering and row selection use DataTable; to edit a single value in a read-only table use InlineCellEdit; for query output use SqlResultTable.
Keyboard interactions
| Key | Action |
|---|---|
| ArrowUporArrowDownorArrowLeftorArrowRight | Moves the active cell. |
| ShiftArrowUporShiftArrowDownorShiftArrowLeftorShiftArrowRight | Grows or shrinks the selected block. |
| CtrlArrowDownorCmdArrowDown | Jumps to the last row. With the other arrows, jumps to the first row, first column or last column. |
| HomeorEnd | Moves to the first or last column. With Ctrl or Cmd, to the first or last cell of the grid. |
| TaborShiftTab | Moves one cell right or left. From the last or first column, focus leaves the grid. |
| EnterorF2 | Edits the active cell, keeping its text. On a checkbox cell, toggles it; on a select cell, opens the options. |
| A-Zor0-9 | Starts editing and replaces the cell's text with the typed character. |
| Space | Toggles a checkbox cell. On a text or number cell, starts editing like any other character. |
| EnterorShiftEnter | While editing, saves and moves down or up. |
| TaborShiftTab | While editing, saves and moves right or left. |
| Escape | While editing, cancels and keeps the old value. Otherwise, shrinks the selection to the active cell. |
| DeleteorBackspace | Clears every editable cell in the selection. Select cells keep their value. |
| CtrlCorCmdC | Copies the selection as tab-separated text. Checkboxes copy as TRUE or FALSE, selects as their label. |
| CtrlVorCmdV | Pastes tab-separated text at the top-left cell of the selection. |
| CtrlZorCmdZ | Undoes the last edit, paste or clear. |
| CtrlAorCmdA | Selects every cell. |
Accessibility
- The
<table>hasrole="grid", the requiredaria-label,aria-rowcount,aria-colcountandaria-multiselectable. Rows carryaria-rowindex(the header row is 1), cells carryaria-colindex, and row numbers are<th scope="row">row headers. - Only the active cell has
tabIndex=0, and focus moves from cell to cell, so the grid is one tab stop. Cells in the selection havearia-selected="true", read-only columns havearia-readonly, and the whole grid isaria-readonlywithoutonRowsChange. - Editors are labelled with the column and row, such as "Price, row 3". Number cells edit in an
<input>withinputMode="decimal", and select cells open a Base UI Select. A checkbox cell's box isinertand the cell holds hidden "checked" or "not checked" text, so the cell stays the only focus stop. - Column resizing is pointer only: the handle on each header edge is
aria-hiddenand has no keyboard control.
Frequently asked questions
How do I paste data from Excel or Google Sheets?
Click the cell where the top-left value should land and press Cmd+V or Ctrl+V. DataGrid reads the tab-separated text both apps copy, including quoted cells with line breaks, fills right and down, and fills a whole selected block when you paste one value. Read-only columns, values that do not fit the column type and anything past the last row or column are skipped: paste never adds rows.
How are pasted or typed numbers parsed?
Number columns drop currency symbols, spaces and thousands commas, so "$1,240.50" becomes 1240.5 and "(1,200)" becomes -1200; a comma that is not a thousands separator, as in "1,5" or "1.240,50", is rejected and the cell keeps its value. Clearing a number cell writes null, so type those fields number | null. Checkbox cells take TRUE, yes, 1 or x, and select cells match an option's value or label.
How do I add a computed column or reject an edit?
Every change arrives in onRowsChange as a whole new array, so recompute there: onRowsChange={(next) => setRows(next.map((r) => ({ ...r, total: r.qty * r.unit })))}, and mark the column readOnly. The grid only shows rows, so an edit you do not store simply disappears. Cmd/Ctrl+Z restores the array from before the last change, up to 50 steps.
Is DataGrid virtualized? How many rows can it handle?
No. It renders every cell, which stays smooth to roughly 2,000 rows. Past that, page the data or build on VirtualList. For sorting, filtering and row selection without cell editing, use DataTable.
Dependencies
Examples
Price list
Text, select, number and checkbox columns, a read-only SKU column and row numbers. Type to edit, Enter to save and move down.
Budget with a computed column
onRowsChange recomputes Total after every edit or paste, and the read-only column skips edits and pastes.
Paste from a spreadsheet
Copy rows from Excel or Google Sheets and paste them at the active cell. "$18.00" becomes the number 18.