# Pivot table

Explore supplied aggregates by row group and column with exact totals and expandable segments.

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

## When to use

- Use it when a page needs explore supplied aggregates by row group and column with exact totals and expandable segments.
- 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 sortable column controls, native row selection and a scrollable table is the actual interface need, rather than pivot table.

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

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

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

## Minimal example

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

## Structured props

- `TidalPivotTable.columns: ReadonlyArray<TidalPivotColumn>`: Required columns value accepted by this exported component.
- `TidalPivotTable.expandedIds: ReadonlyArray<string>`: Required expanded ids value accepted by this exported component.
- `TidalPivotTable.onExpandedChange: (ids: readonly string[], event: MouseEvent<HTMLButtonElement>) => void`: Callback invoked when the expanded change interaction is proposed.
- `TidalPivotTable.onSelectedChange: (selection: TidalPivotSelection, event: MouseEvent<HTMLButtonElement>) => void`: Callback invoked when the selected change interaction is proposed.
- `TidalPivotTable.rows: ReadonlyArray<TidalPivotRow>`: Required rows value accepted by this exported component.
- `TidalPivotTable.selected: TidalPivotSelection | null`: Required selected value accepted by this exported component.
- `TidalPivotTable.title: ReactNode`: Required title value accepted by this exported component.
- `TidalPivotTable.cellProps?: ((row: TidalPivotRow, column: TidalPivotColumn) => ActionProps) | undefined`: Optional cell props value accepted by this exported component.
- `TidalPivotTable.description?: ReactNode`: Optional description value accepted by this exported component.
- `TidalPivotTable.disabled?: boolean | undefined` (default false): Optional disabled value accepted by this exported component.
- `TidalPivotTable.expandProps?: ((row: TidalPivotRow) => ActionProps) | undefined`: Optional expand props value accepted by this exported component.
- `TidalPivotTable.exportProps?: ActionProps | undefined`: Optional export props value accepted by this exported component.
- `TidalPivotTable.formatValue?: ((value: number) => string) | undefined` (default String): Optional format value value accepted by this exported component.
- `TidalPivotTable.grandTotal?: number | null | undefined`: Optional grand total value accepted by this exported component.
- `TidalPivotTable.headingLevel?: "h2" | "h3" | "h4" | "h5" | "h6" | undefined` (default "h2"): Optional heading level value accepted by this exported component.
- `TidalPivotTable.labels?: Partial<{ row: string; total: string; totals: string; missing: string; empty: string; invalid: string; export: string; expand: string; collapse: string; selection: string; }> | undefined` (default {}): Optional labels value accepted by this exported component.
- `TidalPivotTable.onExport?: ((event: MouseEvent<HTMLButtonElement>) => void) | undefined`: Callback invoked when the export interaction is proposed.
- `TidalPivotTable.totals?: Readonly<Record<string, number | null | undefined>> | undefined`: Optional totals value accepted by this exported component.

## Complete usage example

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

import { TidalPivotTable, type TidalPivotRow, type TidalPivotSelection } from "./components/ui/pivot-table";

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



export const pivotColumns = [
  { id: "q1", label: "Q1" },
  { id: "q2", label: "Q2" },
  { id: "q3", label: "Q3" },
];

export const pivotRows: readonly TidalPivotRow[] = [
  {
    id: "north",
    label: "North America",
    values: { q1: 64000, q2: 82000, q3: 96000 },
    total: 242000,
  },
  {
    id: "us",
    label: "United States",
    parentId: "north",
    values: { q1: 48000, q2: 60000, q3: 70000 },
    total: 178000,
  },
  {
    id: "ca",
    label: "Canada",
    parentId: "north",
    values: { q1: 16000, q2: 22000, q3: 26000 },
    total: 64000,
  },
  {
    id: "eu",
    label: "Europe",
    values: { q1: 38000, q2: 46000, q3: 59000 },
    total: 143000,
  },
  {
    id: "uk",
    label: "United Kingdom",
    parentId: "eu",
    values: { q1: 22000, q2: 27000, q3: 35000 },
    total: 84000,
  },
  {
    id: "de",
    label: "Germany",
    parentId: "eu",
    values: { q1: 16000, q2: 19000, q3: 24000 },
    total: 59000,
  },
];

export function PivotTableDemo() {
  const [expanded, setExpanded] = useState<readonly string[]>(["north"]);
  const [selected, setSelected] = useState<TidalPivotSelection | null>({
    rowId: "north",
    columnId: "q3",
  });
  return (
    <TidalPivotTable
      title="Revenue by market"
      description="Compare quarterly revenue. Expand a region to see its markets."
      columns={pivotColumns}
      rows={pivotRows}
      expandedIds={expanded}
      onExpandedChange={setExpanded}
      selected={selected}
      onSelectedChange={setSelected}
      totals={{ q1: 102000, q2: 128000, q3: 155000 }}
      grandTotal={385000}
      formatValue={(v) =>
        new Intl.NumberFormat("en-US", {
          style: "currency",
          currency: "USD",
          maximumFractionDigits: 0,
        }).format(v)
      }
    />
  );
}

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

```

## Gotchas

- Supply truthful data and labels; the component does not fetch, aggregate, or persist records.

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

Consumer-supplied unique columns and rows contain finite numbers, null, or missing values. Rows may identify a parent and supply an explicit total; totals and grandTotal are never calculated or inferred. Up to80 rows and12 columns, acyclic known parents, known selection and expanded groups are validated. Native buttons propose expansion and cell selection after caller-first unprevented events, with owned names, native availability and controlled callbacks. Desktop uses semantic table row/column headers and a locally scrolling surface; narrow containers use per-row description lists. Arrow keys move among available cells, Up/Down preserve the column, Home/End choose first/last, with direction-aware horizontal movement and IME/modifier guards. Exact zero remains0, null or missing means No data. Removed/hidden/disabled owned focus recovers only from source/body to the persistent root. Native root props/ref with React19 cleanup, cell/expand/export native props, optional consumer export callback, translated labels, h2-h6 headings, neutral tokens, RTL and reduced motion are supported. No aggregation, data fetching, file generation, persistence or spreadsheet engine is included.
