---
title: "Data Grid"
description: "A grid that people edit like a spreadsheet, for 10,000 rows and more. People can type in cells, paste a range, undo, and export to CSV."
url: https://gelatinui.com/components/data-grid
markdown_url: https://gelatinui.com/components/data-grid.md
access: pro
install: "npx shadcn@latest add @gelatin-ui-pro/data-grid"
version: "2026-11-11"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Data Grid

> A grid that people edit like a spreadsheet, for 10,000 rows and more. People can type in cells, paste a range, undo, and export to CSV.

Page: https://gelatinui.com/components/data-grid

## When to use it

Best for: Records that people work in all day: many rows, cell editing, paste, and undo.

- Use it when people edit cells in place, or when a table has thousands of rows.
- Use `useDataGridSetup` with an `adapter` to keep the sort, filters, search, and hidden columns in the URL.
- Use `onCommit` for the save: commits run in order on one queue, and a failed save rolls back.

## When not to use it

- For a read-only list with pages, use a [Data Table](https://gelatinui.com/components/data-table.md).
- For a few rows with no state, use a [Table](https://gelatinui.com/components/table.md).

## Notes for agents

- Make the table with `useDataGridSetup`, and pass it as `table`. Keep `columns` and `data` stable.
- Each column needs `meta.label`. Set `meta.editable` and `meta.editor` on a column that people edit.
- A virtual grid has no pages: the URL holds no page, and the Free pagination part does not apply.
- Keep `labels` stable: a new context value renders every drawn row.
- This is a Pro item. Its source ships only after the key check.

## Anatomy

```text
DataGrid
├─ DataGridContent (0..n)
├─ DataGridEmpty (0..n)
├─ DataGridUndo (0..n)
├─ DataGridRedo (0..n)
├─ DataGridSelectAll (0..n)
├─ DataGridGroupBy (0..n)
├─ DataGridExport (0..n)
├─ DataGridVisibleRows (0..n)
├─ DataGridDensity (0..n)
├─ DataGridStatus (0..n)
└─ DataGridCellEditor (0..n)
```

## API reference

### DataGrid

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  |  |
| `status` | `DataStatus` |  | The load state of the rows. Default `ready`. `loading`: the first load, skeleton rows at the real row height, and `aria-busy`. `empty`: the body shows its no rows state. `error`: the rows did not load. With no rows the body shows the error state; with rows on screen (a refresh failed) the rows stay and one line above them says so. |
| `refreshing` | `boolean` |  | New data loads while the old rows stay: a 2px line under the head, and `aria-busy`. |
| `onRetry` | `function` |  | Load the rows again: the Retry button of the error states. Without it, no button. Keep it stable. |
| `density` | `DataTableDensity` |  | The row height (controlled). |
| `defaultDensity` | `DataTableDensity` | "compact" | The row height on the first render (uncontrolled). Default `default` (36px). |
| `onDensityChange` | `function` |  |  |
| `locale` | `string` |  | The locale of the counts. Default: the page locale. |
| `size` | `"default" \| "sm"` |  |  |
| `labels` | `Partial<DataGridLabels>` |  | The words of the grid and of its Free parts (`DATA_GRID_LABELS`). Keep it stable. |
| `table` | `ReactTable<TFeatures, TData, TSelected>` |  | The table from `useDataGridSetup`. |
| `onCommit` | `function` |  | Saves one step: an edit, a paste, an undo, or a redo, with every cell it changes. Steps run one at a time, in order. Before the promise resolves, update your data, with a new object for each changed record (a record that stays the same object draws no change). A rejection rolls the cells back and shows its `Error` message with Retry; no new edit starts until a Retry or a Dismiss. |
| `validate` | `function` |  | Checks a value after the check of the editor kind: return a message to refuse it, else `null`. A paste counts a refused value as skipped. |

Also takes every prop of Base UI `UseRender`: https://base-ui.com/react/components/use-render

### DataGridContent

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | What shows when no row matches: a `DataGridEmpty`. Default: `DataGridEmpty` with its words. |
| `label` | `string` |  | The name of the grid for screen readers ("Invoices"). |
| `height` | `number` | 480 | The height of the scroll box. Default 480px. |

Also takes every prop of Base UI `UseRender`: https://base-ui.com/react/components/use-render

### DataGridEmpty

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### DataGridUndo

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `busy` | `boolean` |  | The button waits for the app (busy words): a spinner, `aria-busy`, and no clicks. Focus stays on the button. The style hook stays `data-loading`. |
| `spinnerPlacement` | `"center" \| "start"` |  | `center` (default): the spinner covers the label. `start`: it takes the leading icon slot. The icon sizes always use `center`, because their one icon is the label. |
| `glass` | `"clear" \| "dark" \| "light"` |  |  |
| `rounded` | `"default" \| "full"` |  |  |
| `size` | `"default" \| "icon" \| "icon-lg" \| "icon-sm" \| "icon-xs" \| "lg" \| "sm" \| "xl" \| "xs"` |  |  |
| `variant` | `"dashed" \| "default" \| "destructive" \| "destructive-outline" \| "ghost" \| "link" \| "media" \| "outline" \| "secondary"` |  |  |

Also takes every prop of Base UI `Button`: https://base-ui.com/react/components/button

### DataGridRedo

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `busy` | `boolean` |  | The button waits for the app (busy words): a spinner, `aria-busy`, and no clicks. Focus stays on the button. The style hook stays `data-loading`. |
| `spinnerPlacement` | `"center" \| "start"` |  | `center` (default): the spinner covers the label. `start`: it takes the leading icon slot. The icon sizes always use `center`, because their one icon is the label. |
| `glass` | `"clear" \| "dark" \| "light"` |  |  |
| `rounded` | `"default" \| "full"` |  |  |
| `size` | `"default" \| "icon" \| "icon-lg" \| "icon-sm" \| "icon-xs" \| "lg" \| "sm" \| "xl" \| "xs"` |  |  |
| `variant` | `"dashed" \| "default" \| "destructive" \| "destructive-outline" \| "ghost" \| "link" \| "media" \| "outline" \| "secondary"` |  |  |

Also takes every prop of Base UI `Button`: https://base-ui.com/react/components/button

### DataGridSelectAll

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `size` | `"default" \| "lg"` |  | `default` 16px, or `lg` 20px. Default: the `CheckboxGroup` size, else `default`. |

Also takes every prop of Base UI `Checkbox.Root`: https://base-ui.com/react/components/checkbox

### DataGridGroupBy

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `columns` | `readonly string[]` |  | The columns people may group by. Default: every column with `enableGrouping` on. |
| `className` | `string` |  |  |

Also takes every prop of Base UI `Menu.Root`: https://base-ui.com/react/components/menu

### DataGridExport

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `busy` | `boolean` |  | The button waits for the app (busy words): a spinner, `aria-busy`, and no clicks. Focus stays on the button. The style hook stays `data-loading`. |
| `spinnerPlacement` | `"center" \| "start"` |  | `center` (default): the spinner covers the label. `start`: it takes the leading icon slot. The icon sizes always use `center`, because their one icon is the label. |
| `glass` | `"clear" \| "dark" \| "light"` |  |  |
| `rounded` | `"default" \| "full"` |  |  |
| `size` | `"default" \| "icon" \| "icon-lg" \| "icon-sm" \| "icon-xs" \| "lg" \| "sm" \| "xl" \| "xs"` |  |  |
| `variant` | `"dashed" \| "default" \| "destructive" \| "destructive-outline" \| "ghost" \| "link" \| "media" \| "outline" \| "secondary"` |  |  |
| `fileName` | `string` | "rows" | The file name, before `.csv`. Default "rows". |

Also takes every prop of Base UI `Button`: https://base-ui.com/react/components/button

### DataGridVisibleRows

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### DataGridDensity

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |
| `fullWidth` | `boolean` |  |  |
| `orientation` | `"horizontal" \| "vertical"` |  |  |
| `rounded` | `"default" \| "full"` |  |  |
| `size` | `"default" \| "lg" \| "sm" \| "xs"` |  |  |
| `options` | `readonly DataTableDensity[]` | GRID_DENSITIES | The row heights to offer. |

Also takes every prop of Base UI `RadioGroup`: https://base-ui.com/react/components/radio-group

### DataGridStatus

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### DataGridCellEditor

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `cell` | `Cell<DataGridFeatures, RowData>` |  |  |
| `rowIndex` | `number` |  |  |

### DataGridEditorValue

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `editor` | `DataGridEditor` |  |  |
| `text` | `string` |  | The cell text. |

### DataGridEditorCell

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `cell` | `Cell` |  |  |
| `column` | `Column` |  |  |
| `getValue` | `Getter<TValue>` |  |  |
| `renderValue` | `Getter<TValue \| null>` |  |  |
| `row` | `Row` |  |  |
| `table` | `Table` |  |  |

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| DataGrid | `data-grid` |  |  |  |
| DataGridContent | `data-grid-content` |  | `--data-grid-width` |  |
| DataGridEmpty | `data-grid-empty` |  |  |  |
| DataGridUndo | `data-grid-undo` |  |  |  |
| DataGridRedo | `data-grid-redo` |  |  |  |
| DataGridSelectAll | `data-grid-select-all` |  |  |  |
| DataGridGroupBy | `data-grid-group-by` |  |  |  |
| DataGridExport | `data-grid-export` |  |  |  |
| DataGridVisibleRows | `data-grid-visible-rows` |  |  |  |
| DataGridDensity | `data-grid-density` |  |  |  |
| DataGridStatus | `data-grid-status` |  |  |  |
| DataGridCellEditor | `data-grid-cell-editor` |  |  |  |

## Usage

Make the table with `useDataGridSetup`, and pass it to the root. The save goes in `onCommit`.

```tsx title="accounts-grid.tsx"
import { createColumnHelper } from "@tanstack/react-table";
import { useState } from "react";

import { DataGrid, DataGridContent, useDataGridSetup } from "@/components/pro/data/data-grid";
import type { DataGridFeatures } from "@/lib/pro/data-grid-model";

type Account = { id: string; name: string; owner: string };

const first: Account[] = [{ id: "a1", name: "Northwind Traders", owner: "Amara Okafor" }];
const column = createColumnHelper<DataGridFeatures, Account>();
const columns = column.columns([
  column.accessor("name", { header: "Account", meta: { label: "Account", editable: true } }),
  column.accessor("owner", { header: "Owner", meta: { label: "Owner" } }),
]);

export function AccountsGrid() {
  const [data, setData] = useState(first);
  const table = useDataGridSetup({ columns, data });
  return (
    <DataGrid
      table={table}
      onCommit={(changes) => {
        setData((rows) => {
          return rows.map((row) => {
            const change = changes.find(({ cell }) => {
              return cell.rowId === row.id;
            });
            return change === undefined ? row : { ...row, name: change.after };
          });
        });
      }}
    >
      <DataGridContent label="Accounts" height={420} />
    </DataGrid>
  );
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui-pro/data-grid
```

It adds 149 registry items: 146 files, 28092 lines, and the npm packages `@base-ui/react`, `@internationalized/date`, `@mantine/hooks`, `@phosphor-icons/react`, `@tanstack/react-hotkeys`, `@tanstack/react-table`, `@tanstack/react-virtual`, `@xstate/react`, `clsx`, `motion`, `react-aria-components`, `tailwind-merge`, `tailwind-variants`, `xstate`.

## Built on

- [Anchor](https://gelatinui.com/components/anchor.md)
- [Avatar](https://gelatinui.com/components/avatar.md)
- [Badge](https://gelatinui.com/components/badge.md)
- [Button](https://gelatinui.com/components/button.md)
- [Checkbox](https://gelatinui.com/components/checkbox.md)
- [Collapsible](https://gelatinui.com/components/collapsible.md)
- [Combobox](https://gelatinui.com/components/combobox.md)
- [Data Table](https://gelatinui.com/components/data-table.md)
- [Date Input](https://gelatinui.com/components/date-input.md)
- [Date Picker](https://gelatinui.com/components/date-picker.md)
- [Drawer](https://gelatinui.com/components/drawer.md)
- [Field](https://gelatinui.com/components/field.md)
- [Frame](https://gelatinui.com/components/frame.md)
- [Input](https://gelatinui.com/components/input.md)
- [Kbd](https://gelatinui.com/components/kbd.md)
- [Menu](https://gelatinui.com/components/menu.md)
- [Rating](https://gelatinui.com/components/rating.md)
- [Segmented Control](https://gelatinui.com/components/segmented-control.md)
- [Select](https://gelatinui.com/components/select.md)
- [Separator](https://gelatinui.com/components/separator.md)
- [Table](https://gelatinui.com/components/table.md)

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Data Table](https://gelatinui.com/components/data-table.md): Pick Data Table for a read-only list of records with sort, filter, and pages.
- [Table](https://gelatinui.com/components/table.md): Pick Table for a few rows of data with no state.
- [Frame](https://gelatinui.com/components/frame.md)

## Keyboard

| Keys | Action |
| --- | --- |
| Arrow keys, Home, End, Page Up, Page Down | Move the ring between cells. Ctrl or Cmd with Home or End goes to the first or last row. |
| Enter, F2 | Starts an edit in the cell. A typed key starts one too. |
| Tab, Escape | In an editor, Tab commits and moves. Escape cancels. |
| Shift + arrow keys | Selects a range of cells. |
| Mod+C, Mod+V | Copies the range as tab-separated text, and pastes with a preview. |
| Mod+Z, Mod+Shift+Z | Undoes and redoes a commit. |
| Alt+Left Arrow, Alt+Right Arrow | On a head cell, changes the column width by 16px. |

## Accessibility

`DataGridContent` takes a `label` that names the grid, and the table has the `grid` role.

The grid has one Tab stop, and the arrow keys move focus between cells.

`aria-rowcount` and `aria-rowindex` give the place of a row, also when only the rows in view are drawn.

## Motion

| Part | Motion |
| --- | --- |
| Paste and save bars in | toast · 300ms · ease-panel (0.2, 0.4, 0.2, 1) · slide up 4px and fade in |
| Paste and save bars out | toast-exit · 150ms · ease-out (0, 0, 0.2, 1) · slide down 4px and fade out |
