Skip to content
Sign in
DataPivot tableMenu

Pivot tablePro

Drag fields into rows, columns and values, with subtotals, grand totals and value tinted cells. Every drag has a keyboard twin.

ProNew revenue by region and plan across quarters, with subtotals; drag or use Space and arrows to move fields.

Installation

$ pnpm dlx shadcn@latest add @chatcn-pro/pivot-table

Usage

tsx
import { PivotTable } from "@/components/ui/chatcn/pro/pivot-table"

<PivotTable
  data={rows}
  fields={fields}
  defaultValue={{ rows: ["region", "plan"], columns: ["quarter"], values: [{ field: "revenue", agg: "sum" }] }}
/>

Fields are dimensions or measures; a measure dropped in Values sums by default and a dimension counts distinct values. Two or more row fields add a subtotal per group. Cells tint with the first chart color by their share of the largest value; set heat={false} for plain cells. pivot in chatcn-pro-data-a does the aggregation, so you can run it on the server for big data.

Examples

States

ProTwo values by country without heat, nothing placed yet, loading and error.

Props

PropTypeNotes
dataRecord<string, unknown>[]Rows to pivot
fieldsPivotField[]{ id, label?, kind, format? }
value, defaultValue, onValueChangePivotConfig{ rows, columns, values: { field, agg }[] }
heatbooleanDefault true
loading, error, onRetry, maxHeight, title, localePivot states

Keyboard

KeyAction
Space or Enter on a fieldPicks it up or drops it
Up and Down while heldMoves it to the previous or next well
Left and Right while heldReorders it inside the well
Escape while heldPuts it back where it was
Delete on a placed fieldReturns it to Fields

Accessibility

  • Fields are buttons with a draggable role description and instructions; every move is announced.
  • The table has a caption naming the values and groupings, and scoped row and column headers.
  • Aggregates change from a menu on each value field.

Motion

The dragged field follows the pointer one to one; the target well tints and an insertion bar shows where it lands. Drops and keyboard moves are instant.