# Data table

Sortable column controls, native row selection and a scrollable table.

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

## When to use

- Use it when a page needs sortable column controls, native row selection and a scrollable table.
- Choose it when the data structure, labels, and state are supplied by the application and must remain consumer controlled.

## Alternatives

- Choose data-grid instead when use the grid for keyboard cell navigation, inline editing, and controlled row selection.

## 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 table

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

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

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/data-table.css";
import{TidalDataTable}from"./components/ui/data-table";
export default()=><div className="tidal-scope"><TidalDataTable caption={"Demo"} columns={[{id:"example",label:"Demo",cell:() => "value"}]} getRowId={() => "value"} rows={[{ id: "example" }]}/></div>;
```

## Structured props

- `TidalDataTable.caption: string`: Required caption value accepted by this exported component.
- `TidalDataTable.columns: ReadonlyArray<TidalTableColumn<T>>`: Required columns value accepted by this exported component.
- `TidalDataTable.getRowId: (row: T) => string`: Required get row id value accepted by this exported component.
- `TidalDataTable.rows: ReadonlyArray<T>`: Required rows value accepted by this exported component.
- `TidalDataTable.busy?: boolean | undefined` (default false): Optional busy value accepted by this exported component.
- `TidalDataTable.disabled?: boolean | undefined` (default false): Optional disabled value accepted by this exported component.
- `TidalDataTable.empty?: ReactNode` (default "No results."): Optional empty value accepted by this exported component.
- `TidalDataTable.maxHeight?: number | undefined`: Optional max height value accepted by this exported component.
- `TidalDataTable.minTableWidth?: number | undefined` (default 640): Optional min table width value accepted by this exported component.
- `TidalDataTable.onSortChange?: ((sort: TidalTableSort | null) => void) | undefined`: Callback invoked when the sort change interaction is proposed.
- `TidalDataTable.selection?: TidalTableSelection<T> | undefined`: Optional selection value accepted by this exported component.
- `TidalDataTable.sort?: TidalTableSort | null | undefined`: Optional sort value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/data-table.tsx) | [Manifest](https://tidalui.com/examples/data-table.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 { useLayoutEffect, useRef, useState } from "react";

import { ArrowUpRight, Folder, Search, X, ChevronLeft, ChevronRight, RotateCcw } from "lucide-react";

import { TidalDataTable, type TidalTableColumn, type TidalTableSort } from "./components/ui/data-table";

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

function tidalExampleAvatarDataUri(seed: unknown) {
  const text = String(seed).replace(/[^a-z0-9]/gi, "").slice(-2) || "UI";
  const palette = ["#333333", "#555555", "#777777", "#999999", "#bbbbbb"];
  const color = palette[Array.from(text).reduce((sum, character) => sum + character.charCodeAt(0), 0) % palette.length];
  const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 96 96"><rect width="96" height="96" rx="48" fill="${color}"/><circle cx="48" cy="38" r="17" fill="white" fill-opacity=".92"/><path d="M18 92c3-22 15-34 30-34s27 12 30 34" fill="white" fill-opacity=".92"/></svg>`;
  return `data:image/svg+xml,${encodeURIComponent(svg)}`;
}

function tidalExampleImageDataUri(label: string) {
  const safeLabel = label.replace(/[<>&]/g, "").slice(0, 28) || "Sample image";
  const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 675"><defs><linearGradient id="g" x1="0" x2="1" y1="0" y2="1"><stop stop-color="#171717"/><stop offset="1" stop-color="#555555"/></linearGradient></defs><rect width="1200" height="675" fill="url(#g)"/><circle cx="950" cy="100" r="260" fill="white" fill-opacity=".08"/><text x="80" y="570" fill="white" font-family="system-ui,sans-serif" font-size="64" font-weight="700">${safeLabel}</text></svg>`;
  return `data:image/svg+xml,${encodeURIComponent(svg)}`;
}

const tidalExampleStyles = ".tidal-scope .data-table-specimen{container:table-demo/inline-size;width:100%;max-width:900px;min-width:0;padding:28px;border:1px solid var(--t-border);border-radius:var(--t-radius-card);background:var(--t-subtle);box-shadow:0 22px 44px -32px #00000033;color:var(--t-ink)}.tidal-scope .data-table-demo-title{display:flex;justify-content:space-between;align-items:center;gap:12px;margin-bottom:22px}.tidal-scope .data-table-demo-title h3{font-size:22px;letter-spacing:-.7px;font-weight:500;line-height:1.2;margin:0 0 4px}.tidal-scope .data-table-demo-title p{font-size:11px;color:var(--t-muted);margin:0}.tidal-scope .data-table-demo-title>span{font-size:11px;border:1px solid var(--t-border);padding:4px 7px;border-radius:6px;color:var(--t-muted)}.tidal-scope .data-table-demo-toolbar{display:flex;gap:10px;align-items:center;justify-content:space-between;margin-bottom:14px}.tidal-scope .data-table-demo-search{display:flex;align-items:center;gap:8px;min-width:0;width:260px;max-width:100%;min-height:44px;border:1px solid var(--t-border);border-radius:9px;padding:0 12px;background:var(--t-surface);color:var(--t-muted)}.tidal-scope .data-table-demo-search:focus-within{outline:2px solid var(--t-accent);outline-offset:-2px}.tidal-scope .data-table-demo-search input{width:100%;min-width:0;min-height:44px;font:inherit;font-size:11px;padding:0;border:0;outline:0;background:transparent;color:var(--t-ink)}.tidal-scope .table-demo-reset,.tidal-scope .table-demo-open{display:grid;place-items:center;width:44px;min-width:44px;height:44px;flex:none;padding:0;border:1px solid transparent;border-radius:8px;background:transparent;color:var(--t-muted);cursor:pointer;transition:background 140ms,transform 180ms}.tidal-scope .table-demo-reset{border-color:var(--t-border);background:var(--t-surface)}.tidal-scope .table-demo-open:hover,.tidal-scope .table-demo-reset:hover{background:var(--t-wash);color:var(--t-ink)}.tidal-scope .table-demo-open:focus-visible,.tidal-scope .table-demo-reset:focus-visible{outline:2px solid var(--t-accent);outline-offset:-3px}.tidal-scope .table-demo-open:active{transform:scale(.94)}.tidal-scope .table-demo-project{display:flex;align-items:center;gap:10px;min-width:0}.tidal-scope .table-demo-project>span{display:grid;place-items:center;flex:none;width:30px;height:33px;border:1px solid var(--t-border);background:var(--t-subtle);border-radius:7px;color:var(--t-muted)}.tidal-scope .table-demo-project>strong{font-size:11px;font-weight:500;min-width:0;overflow-wrap:anywhere}.tidal-scope .table-demo-status{display:inline-flex;align-items:center;gap:6px;padding:4px 7px;border:1px solid var(--t-border);border-radius:5px;font-size:11px;white-space:nowrap;color:var(--t-muted)}.tidal-scope .table-demo-status>i{width:5px;height:5px;border-radius:50%;border:1px solid var(--t-muted)}.tidal-scope .table-demo-status[data-complete=true]{color:var(--t-ink)}.tidal-scope .table-demo-status[data-complete=true]>i{background:var(--t-ink);border-color:var(--t-ink)}.tidal-scope .table-demo-owner{display:flex;align-items:center;gap:7px;font-size:11px;white-space:nowrap}.tidal-scope .table-demo-owner img{width:22px;height:22px;border-radius:50%;object-fit:cover}.tidal-scope .table-demo-tasks{font-size:11px;font-variant-numeric:tabular-nums}.tidal-scope .data-table-demo-footer{padding:0;border:0;width:100%;max-width:none;margin:10px 0 0;display:flex;justify-content:space-between;align-items:center;gap:10px;font-size:11px;color:var(--t-muted);margin-top:10px}.tidal-scope .data-table-demo-footer nav{display:flex;align-items:center;gap:5px}.tidal-scope .data-table-demo-footer nav>span{min-width:35px;text-align:center;font-size:11px;font-variant-numeric:tabular-nums}.tidal-scope .data-table-demo-footer nav>button{display:grid;place-items:center;width:44px;height:44px;padding:0;border:1px solid var(--t-border);border-radius:8px;background:var(--t-surface);color:var(--t-ink);cursor:pointer;transition:background 140ms}.tidal-scope .data-table-demo-footer nav>button:hover:not([aria-disabled=true]){background:var(--t-wash)}.tidal-scope .data-table-demo-footer nav>button[aria-disabled=true]{opacity:.4;cursor:not-allowed}.tidal-scope .data-table-demo-footer nav>button:focus-visible{outline:2px solid var(--t-accent);outline-offset:-3px}.tidal-scope .data-table-demo-detail{display:flex;justify-content:space-between;gap:10px;align-items:center;border:1px solid var(--t-border);border-radius:10px;padding:10px 12px;margin-top:12px;background:var(--t-surface)}.tidal-scope .data-table-demo-detail>div{display:flex;flex-direction:column;min-width:0;gap:3px}.tidal-scope .data-table-demo-detail h4{margin:0;font-size:12px;font-weight:500;overflow-wrap:anywhere}.tidal-scope .data-table-demo-detail h4:focus{outline:0}.tidal-scope .data-table-demo-detail span{font-size:11px;color:var(--t-muted)}.tidal-scope .data-table-demo-note{font-size:11px;color:var(--t-muted);line-height:1.6;margin:13px 0 0}@media(max-width:480px){.tidal-scope .data-table-specimen{padding:18px}}@keyframes table-demo-detail-in{from{opacity:0;transform:translateY(5px)}to{opacity:1;transform:none}}@media(prefers-reduced-motion:no-preference){.tidal-scope .data-table-demo-detail{animation:table-demo-detail-in 300ms var(--t-ease-out) both}}@media(prefers-reduced-motion:reduce){.tidal-scope .table-demo-open:active{transform:none}}\n\n.tidal-scope .table-demo-scroll-hint{display:none}@container table-demo (max-width:700px){.tidal-scope .table-demo-scroll-hint{display:inline}}";

const records = [
  {
    id: "website",
    name: "Website",
    status: "In review",
    owner: "Ava Chen",
    tasks: 24,
    portrait: 1,
  },
  {
    id: "mobile",
    name: "Mobile app",
    status: "In progress",
    owner: "Noah Reed",
    tasks: 18,
    portrait: 2,
  },
  {
    id: "brand",
    name: "Brand assets",
    status: "Complete",
    owner: "Mila Stone",
    tasks: 12,
    portrait: 3,
  },
  {
    id: "docs",
    name: "Documentation",
    status: "In progress",
    owner: "Eli Park",
    tasks: 16,
    portrait: 4,
  },
  {
    id: "onboarding",
    name: "Onboarding",
    status: "In review",
    owner: "Ava Chen",
    tasks: 9,
    portrait: 1,
  },
  {
    id: "research",
    name: "User research",
    status: "Complete",
    owner: "Noah Reed",
    tasks: 8,
    portrait: 2,
  },
];

type Project = (typeof records)[number];

export function DataTableDemo() {
  const [query, setQuery] = useState(""),
    [sort, setSort] = useState<TidalTableSort | null>(null),
    [selected, setSelected] = useState<Set<string>>(new Set()),
    [page, setPage] = useState(1),
    [detail, setDetail] = useState<string | null>(null),
    [revision, setRevision] = useState(0);
  const detailHeading = useRef<HTMLHeadingElement>(null),
    opener = useRef<HTMLButtonElement | null>(null),
    search = useRef<HTMLInputElement>(null);
  useLayoutEffect(() => {
    if (detail) detailHeading.current?.focus({ preventScroll: true });
  }, [detail]);
  function closeDetail() {
    setDetail(null);
    if (opener.current?.isConnected)
      opener.current.focus({ preventScroll: true });
    else search.current?.focus({ preventScroll: true });
  }
  const filtered = records.filter((r) =>
    `${r.name} ${r.status} ${r.owner}`
      .toLowerCase()
      .includes(query.toLowerCase().trim()),
  );
  const ordered = sort
    ? [...filtered].sort((a, b) => {
        const v =
          sort.column === "tasks"
            ? a.tasks - b.tasks
            : String(a[sort.column as keyof Project] ?? "").localeCompare(
                String(b[sort.column as keyof Project] ?? ""),
                "en",
              );
        return sort.direction === "asc" ? v : -v;
      })
    : filtered;
  const count = Math.max(1, Math.ceil(ordered.length / 3)),
    current = Math.min(page, count),
    visible = ordered.slice((current - 1) * 3, current * 3),
    opened = records.find((r) => r.id === detail);
  const columns: TidalTableColumn<Project>[] = [
    {
      id: "name",
      label: "Project",
      sortable: true,
      rowHeader: true,
      width: 210,
      cell: (r) => (
        <span className="table-demo-project">
          <span aria-hidden="true">
            <Folder size={16} />
          </span>
          <strong>{r.name}</strong>
        </span>
      ),
    },
    {
      id: "status",
      label: "Status",
      sortable: true,
      width: 130,
      cell: (r) => (
        <span
          className="table-demo-status"
          data-complete={r.status === "Complete"}
        >
          <i aria-hidden="true" />
          {r.status}
        </span>
      ),
    },
    {
      id: "owner",
      label: "Owner",
      sortable: true,
      width: 140,
      cell: (r) => (
        <span className="table-demo-owner">
          <img src={tidalExampleAvatarDataUri(r.portrait)} alt="" />
          {r.owner}
        </span>
      ),
    },
    {
      id: "tasks",
      label: "Tasks",
      sortable: true,
      align: "end",
      width: 75,
      cell: (r) => <span className="table-demo-tasks">{r.tasks}</span>,
    },
    {
      id: "actions",
      label: "Details",
      align: "end",
      width: 70,
      cell: (r) => (
        <button
          className="table-demo-open"
          type="button"
          aria-label={`Show ${r.name} details`}
          onClick={(e) => {
            opener.current = e.currentTarget;
            setDetail(r.id);
          }}
        >
          <ArrowUpRight size={17} aria-hidden="true" />
        </button>
      ),
    },
  ];
  return (
    <div className="data-table-specimen">
      <header className="data-table-demo-title">
        <div>
          <h3>Projects</h3>
          <p>Sample workspace</p>
        </div>
        <span>{records.length} total</span>
      </header>
      <div className="data-table-demo-toolbar">
        <label className="data-table-demo-search">
          <Search size={15} aria-hidden="true" />
          <input
            ref={search}
            type="search"
            aria-label="Search sample projects"
            placeholder="Search projects…"
            value={query}
            onChange={(e) => {
              setQuery(e.target.value);
              setPage(1);
            }}
          />
        </label>
        <button
          type="button"
          className="table-demo-reset"
          aria-label="Reset sample table"
          onClick={() => {
            setQuery("");
            setSort(null);
            setSelected(new Set());
            setPage(1);
            setDetail(null);
            setRevision((n) => n + 1);
          }}
        >
          <RotateCcw size={15} aria-hidden="true" />
        </button>
      </div>
      <TidalDataTable
        key={revision}
        caption="Sample projects"
        columns={columns}
        rows={visible}
        getRowId={(r) => r.id}
        sort={sort}
        onSortChange={(next) => {
          setSort(next);
          setPage(1);
        }}
        selection={{
          selectedIds: selected,
          onSelectionChange: setSelected,
          getRowLabel: (r) => r.name,
        }}
        empty="No sample projects match this search."
      />
      <footer className="data-table-demo-footer">
        <span role="status">
          {selected.size
            ? `${selected.size} selected`
            : `${filtered.length} results`}
        </span>
        <nav aria-label="Sample table pages">
          <button
            type="button"
            aria-label="Previous sample table page"
            aria-disabled={current === 1}
            onClick={() => {
              if (current > 1) setPage(current - 1);
            }}
          >
            <ChevronLeft size={15} aria-hidden="true" />
          </button>
          <span>
            {current} / {count}
          </span>
          <button
            type="button"
            aria-label="Next sample table page"
            aria-disabled={current === count}
            onClick={() => {
              if (current < count) setPage(current + 1);
            }}
          >
            <ChevronRight size={15} aria-hidden="true" />
          </button>
        </nav>
      </footer>
      {opened ? (
        <section
          className="data-table-demo-detail"
          aria-label={`${opened.name} sample details`}
        >
          <div>
            <h4 ref={detailHeading} tabIndex={-1}>
              {opened.name}
            </h4>
            <span>
              {opened.tasks} tasks · {opened.status}
            </span>
          </div>
          <button
            type="button"
            className="table-demo-open"
            aria-label="Close sample details"
            onClick={closeDetail}
          >
            <X size={16} aria-hidden="true" />
          </button>
        </section>
      ) : null}
      <p className="data-table-demo-note">
        <span className="table-demo-scroll-hint">
          Scroll horizontally to see all columns.{" "}
        </span>
        Sort columns, select rows or explore the sample records.
      </p>
    </div>
  );
}

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

```

## Gotchas

- The host application owns data, validation, persistence, navigation, and service side effects described by this API.

## 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."],"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."}

Generic native table. Required caption, columns([{id,label,cell(row),sortable?,rowHeader?,align:start|end,width?}]), rows and getRowId returning unique nonempty strings. Root forwards native div attributes/ref. Caption is visually hidden; consumers may render a visible matching heading outside. Semantic col headers, optional row headers, aria-sort and native buttons; sort/onSortChange metadata cycle ascending→descending→unsorted. Consumers supply the actual sorted, filtered and paged row order; the component never silently transforms data or fetches records. Optional selection contains controlled selectedIds ReadonlySet, onSelectionChange, getRowLabel(defaultID) and isRowDisabled(selection only). Native checkbox inputs are44px with true mixed state; select-all affects only selectable rows currently supplied and preserves off-page/disabled IDs. No callback renders read-only disabled selection. Disabled blocks selection and sort controls; busy only marks the table aria-busy and does not disable actions. No named form fields or implicit submission is added by selection. Optional empty ReactNode(defaultNo results), minTableWidth(default640, invalid falls back640) and maxHeight(positivefinite pixels) control presentation. The named scroll region supports native horizontal/vertical keyboard scrolling; sticky header preserves column context. Full labels wrap; caller cell content owns its own controls and accessibility. Invalid or duplicate row/column IDs produce visible configuration feedback instead of ambiguous keys. All callbacks are consumer-owned; React state, routing, dialogs, requests, forms, sorting algorithms, page data and focus after replacing custom cell content belong to the consumer. Shared neutral tokens, finite bounded45ms row entrance, clear selected-row surfaces and static reduced motion. No request, storage, timer, global listener or automatic row action is introduced.
