# Data grid

Edit and select consumer-owned records with contained spreadsheet keyboard movement.

Access: pro. Category: Data. Kind: composite.

## When to use

- Use it when a page needs edit and select consumer-owned records with contained spreadsheet keyboard movement.
- Choose it when the data structure, labels, and state are supplied by the application and must remain consumer controlled.

## Alternatives

- Choose data-table instead when use the table for read-oriented records that do not need spreadsheet-style cell interaction.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install Data grid

```sh
npx shadcn@latest add @tidal-pro/data-grid
```

Stylesheets: `components/ui/tidal.css`, `components/ui/data-grid.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/data-grid.css";
import{TidalDataGrid}from"./components/ui/data-grid";
export default(p:Parameters<typeof TidalDataGrid>[0])=><div className="tidal-scope"><TidalDataGrid {...p}/></div>;
```

## Structured props

- `TidalDataGrid.activeCell: TidalDataGridCell | null`: Required active cell value accepted by this exported component.
- `TidalDataGrid.caption: string`: Required caption value accepted by this exported component.
- `TidalDataGrid.columns: ReadonlyArray<TidalDataGridColumn<T>>`: Required columns value accepted by this exported component.
- `TidalDataGrid.editingCell: TidalDataGridCell | null`: Required editing cell value accepted by this exported component.
- `TidalDataGrid.editValue: string`: Required edit value value accepted by this exported component.
- `TidalDataGrid.getRowId: (row: T) => string`: Required get row id value accepted by this exported component.
- `TidalDataGrid.getRowLabel: (row: T) => string`: Required get row label value accepted by this exported component.
- `TidalDataGrid.onActiveCellChange: (cell: TidalDataGridCell, event: SyntheticEvent<HTMLElement>) => void`: Callback invoked when the active cell change interaction is proposed.
- `TidalDataGrid.onCellCommit: (cell: TidalDataGridCell, value: string, event: FormEvent<HTMLFormElement>) => void`: Callback invoked when the cell commit interaction is proposed.
- `TidalDataGrid.onEditingCellChange: (cell: TidalDataGridCell | null, event: SyntheticEvent<HTMLElement>) => void`: Callback invoked when the editing cell change interaction is proposed.
- `TidalDataGrid.onEditValueChange: (value: string, event: ChangeEvent<HTMLInputElement>) => void`: Callback invoked when the edit value change interaction is proposed.
- `TidalDataGrid.rows: ReadonlyArray<T>`: Required rows value accepted by this exported component.
- `TidalDataGrid.cancelButtonProps?: Omit<ButtonHTMLAttributes<HTMLButtonElement>, "disabled" | "type" | "aria-disabled" | OwnedMarkup> | undefined`: Optional cancel button props value accepted by this exported component.
- `TidalDataGrid.cancelButtonRef?: Ref<HTMLButtonElement> | undefined`: Optional cancel button ref value accepted by this exported component.
- `TidalDataGrid.description?: ReactNode`: Optional description value accepted by this exported component.
- `TidalDataGrid.disabled?: boolean | undefined` (default false): Optional disabled value accepted by this exported component.
- `TidalDataGrid.labels?: Partial<TidalDataGridLabels> | undefined`: Optional labels value accepted by this exported component.
- `TidalDataGrid.readOnly?: boolean | undefined` (default false): Optional read only value accepted by this exported component.
- `TidalDataGrid.saveButtonProps?: Omit<ButtonHTMLAttributes<HTMLButtonElement>, "disabled" | "form" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "type" | "aria-disabled" | OwnedMarkup> | undefined`: Optional save button props value accepted by this exported component.
- `TidalDataGrid.saveButtonRef?: Ref<HTMLButtonElement> | undefined`: Optional save button ref value accepted by this exported component.
- `TidalDataGrid.selection?: TidalDataGridSelection<T> | undefined`: Optional selection value accepted by this exported component.
- `TidalDataGrid.tableProps?: Omit<TableHTMLAttributes<HTMLTableElement>, "role" | "aria-colcount" | "aria-rowcount" | OwnedMarkup> | undefined`: Optional table props value accepted by this exported component.
- `TidalDataGrid.tableRef?: Ref<HTMLTableElement> | undefined`: Optional table ref value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/data-grid.tsx) | [Manifest](https://tidalui.com/examples/data-grid.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
import "./components/ui/tidal.css";

import { useId, useState, type FormEvent, type SyntheticEvent } from "react";

import { TidalDataGrid, type TidalDataGridCell, type TidalDataGridColumn } from "./components/ui/data-grid";

import "./components/ui/data-grid.css";



const tidalExampleStyles = ".data-grid-demo {\n  inline-size: 100%;\n  max-inline-size: 860px;\n  min-inline-size: 0;\n}\n.data-grid-demo-status {\n  display: block;\n  min-block-size: 20px;\n  margin-block-start: 12px;\n  color: var(--t-ink);\n  font-size: 12px;\n  line-height: 1.5;\n}\n.data-grid-demo-note {\n  margin: 3px 0 0;\n  color: var(--t-muted);\n  font-size: 11px;\n  line-height: 1.5;\n}";

interface ProjectRow {
  id: string;
  project: string;
  owner: string;
  seats: string;
  status: string;
}

const INITIAL_ROWS: ProjectRow[] = [
  {
    id: "atlas",
    project: "Atlas onboarding",
    owner: "Mira Chen",
    seats: "18",
    status: "In review",
  },
  {
    id: "relay",
    project: "Relay workspace",
    owner: "Owen Price",
    seats: "32",
    status: "Active",
  },
  {
    id: "field",
    project: "Field notes",
    owner: "Sam Rivera",
    seats: "7",
    status: "Draft",
  },
];

export function DataGridDemo() {
  const statusId = useId().replace(/:/g, "");
  const [rows, setRows] = useState(INITIAL_ROWS);
  const [selected, setSelected] = useState<Set<string>>(new Set(["relay"]));
  const [activeCell, setActiveCell] = useState<TidalDataGridCell | null>({
    rowId: "atlas",
    columnId: "project",
  });
  const [editingCell, setEditingCell] = useState<TidalDataGridCell | null>(
    null,
  );
  const [editValue, setEditValue] = useState("");
  const [errors, setErrors] = useState<Record<string, string>>({});
  const [status, setStatus] = useState("Select a cell or use the arrow keys.");

  const columns: readonly TidalDataGridColumn<ProjectRow>[] = [
    {
      id: "project",
      header: "Project",
      accessibleLabel: "Project",
      renderCell: (row) => row.project,
      getEditValue: (row) => row.project,
      width: 220,
      error: (row) => errors[`${row.id}:project`],
    },
    {
      id: "owner",
      header: "Owner",
      accessibleLabel: "Owner",
      renderCell: (row) => row.owner,
      getEditValue: (row) => row.owner,
      width: 180,
      error: (row) => errors[`${row.id}:owner`],
    },
    {
      id: "seats",
      header: "Seats",
      accessibleLabel: "Seats",
      renderCell: (row) => row.seats,
      getEditValue: (row) => row.seats,
      inputType: "number",
      width: 110,
      align: "end",
      editorProps: () => ({ min: "0", inputMode: "numeric" }),
      error: (row) => errors[`${row.id}:seats`],
    },
    {
      id: "status",
      header: "Status",
      accessibleLabel: "Status",
      renderCell: (row) => row.status,
      width: 140,
    },
  ];

  function beginEditing(
    cell: TidalDataGridCell | null,
    event: SyntheticEvent<HTMLElement>,
  ) {
    if (!cell) {
      setEditingCell(null);
      setStatus("Edit cancelled.");
      return;
    }
    const row = rows.find((item) => item.id === cell.rowId);
    const column = columns.find((item) => item.id === cell.columnId);
    if (!row || !column?.getEditValue) return;
    setEditValue(column.getEditValue(row));
    setEditingCell(cell);
    setStatus(
      `Editing ${column.accessibleLabel.toLowerCase()} for ${row.project}.`,
    );
    if (event.defaultPrevented) return;
  }

  function commit(
    cell: TidalDataGridCell,
    value: string,
    event: FormEvent<HTMLFormElement>,
  ) {
    event.preventDefault();
    const next = value.trim();
    const key = `${cell.rowId}:${cell.columnId}`;
    if (
      !next ||
      (cell.columnId === "seats" && (!/^\d+$/.test(next) || Number(next) > 999))
    ) {
      setErrors((current) => ({
        ...current,
        [key]:
          cell.columnId === "seats"
            ? "Enter 0 to 999 seats."
            : "Enter a value.",
      }));
      setStatus("Correct the highlighted cell.");
      return;
    }
    setRows((current) =>
      current.map((row) =>
        row.id === cell.rowId ? { ...row, [cell.columnId]: next } : row,
      ),
    );
    setErrors((current) => {
      const copy = { ...current };
      delete copy[key];
      return copy;
    });
    setEditingCell(null);
    setStatus("Local sample row updated.");
  }

  return (
    <div className="data-grid-demo">
      <TidalDataGrid
        caption="Project capacity"
        description="Edit the project, owner or seat count. Status is read only."
        rows={rows}
        columns={columns}
        getRowId={(row) => row.id}
        getRowLabel={(row) => row.project}
        activeCell={activeCell}
        onActiveCellChange={(cell) => setActiveCell(cell)}
        editingCell={editingCell}
        editValue={editValue}
        onEditingCellChange={beginEditing}
        onEditValueChange={(value) => setEditValue(value)}
        onCellCommit={commit}
        selection={{
          selectedRowIds: selected,
          onSelectionChange: (ids) => {
            setSelected(ids);
            setStatus(
              `${ids.size} ${ids.size === 1 ? "row" : "rows"} selected.`,
            );
          },
          getRowLabel: (row) => row.project,
        }}
      />
      <output
        id={statusId}
        className="data-grid-demo-status"
        aria-live="polite"
      >
        {status}
      </output>
      <p className="data-grid-demo-note">
        Sample records only. Changes stay in this preview.
      </p>
    </div>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <DataGridDemo />
    </div>
  );
}

```

## Gotchas

- The consumer owns row identity, edit state, validation, commit behavior, and persistence.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"keyboard":["Tab and Shift+Tab follow the component's native focus order.","Arrow-key behavior follows the exported composite-control implementation.","Escape dismisses the open overlay where the underlying primitive supports dismissal."],"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

caption, rows, columns, getRowId, getRowLabel, controlled activeCell/onActiveCellChange, controlled editingCell/editValue/onEditingCellChange/onEditValueChange, and onCellCommit are required. Columns require unique nonblank IDs, exact accessible labels and consumer cell rendering; optional getEditValue enables one native text, email, number, URL or telephone editor. The localized editCell label names an editor unless its native props provide aria-label or aria-labelledby. Optional consumer error content is linked to the exact cell editor. Arrow keys move across the roving grid, logical left/right follow direction, Home/End move within a row, Enter/F2 begins editing, and Escape cancels without leaving the grid. Focus reveal is limited to the grid scroller. Optional controlled row selection uses native checkboxes and a consumer callback. Root/table/cell/editor/selection/save/cancel native attributes and refs are supported with owned values, markup, external form reassociation, availability and roving state excluded and runtime-stripped. disabled and readOnly preserve native control semantics. Consumers own validation, record updates, selection, sorting/filtering before rows are passed, persistence and all external effects. Column resizing/reordering, formulas, virtualization, clipboard access, network and storage are not bundled.
