Table
A styled, accessible data table with sortable headers and row activation. @startingPoint section="Data" subtitle="Sortable, selectable data table with density modes" viewport="760x320"
Signature
Density
Viewport
Theme and light/dark are set in the top barWhen to use
- Use it when Straightforward, sortable tabular data without heavy interaction.
- Reach for something else when Filtering, saved views or inline edit — use
DataGrid.
Accessibility
Rendered as a real <table> with header scopes; sortable columns expose aria-sort. Row selection and actions are keyboard reachable.
Install and import
npx shadcn@latest add @prism/table
import { Table } from '@/components/prism/Table';
In a no-build prototype, read it from the bundle instead: const { Table } = window.PrismDesignSystem_39d121;
Props
| Prop | Type | Required | Description |
|---|---|---|---|
columns | TableColumn[] | Yes | |
rows | any[] | Yes | |
rowKey | string | — | Field holding each row's key, e.g. "slug". Serializable, so it works from a server component. Default: row.id, else the index. The key must be plain text: if that field holds an element, the row falls back to its index. |
getRowKey | (row: any, index: number) => string | number | — | Function form of rowKey (client components only). Wins over rowKey. |
caption | React.ReactNode | — | |
density | "comfortable" | "compact" | — | compact tightens padding for dense reports. |
verticalAlign | "top" | "middle" | — | "top" aligns every cell to the top (cells with a field plus a caption). Default middle. |
hoverable | boolean | — | |
isStriped | boolean | — | Subtle zebra striping. Default true. |
isSelectable | boolean | — | Show a checkbox column with select-all. |
selectedKeys | (string | number)[] | — | |
onSelectionChange | (keys: (string | number)[]) => void | — | |
onRowAction | (row: any) => void | — | Makes rows actionable. Each row gets a real <button> in its first column cell (visually hidden) for keyboard and screen-reader users; a click anywhere on the row runs it too. Client components only (it's a function). |
rowLabel | string | — | Field holding each row's accessible name (its action button, expand toggle and checkbox), e.g. "name". Server-safe. Default: the first column's text. |
getRowLabel | (row: any) => string | — | Function form of rowLabel (client components only). Wins over rowLabel. |
disabledKeys | (string | number)[] | — | Keys of rows that can't be activated or selected. Server-safe. The row's action is aria-disabled (still focusable, announced as unavailable). |
isRowDisabled | (row: any) => boolean | — | Function form of disabledKeys (client components only). |
headerGroups | TableHeaderGroup[] | — | Header bands spanning several columns, e.g. [{ label: "Fees", columns: ["setup", "perStudent"] }]. Renders a <th scope="colgroup"> band row above the column headers; ungrouped columns span both rows. A group split by other columns repeats its label over each run. Server-safe. |
sortDescriptor | SortDescriptor | — | |
onSortChange | (descriptor: SortDescriptor) => void | — | |
rowTone | string | — | Field holding each row's tone ("negative" | "notice" | "positive"), e.g. "tone". Serializable, so it works from a server component. A toned row gets a tint and a leading edge bar (solid / dashed / thin by tone). Say why in a cell too (a Badge). |
getRowTone | (row: any) => TableRowTone | undefined | null | — | Function form of rowTone (client components only). Wins over rowTone. |
renderDetail | (row: any) => React.ReactNode | — | Detail panel for a row: adds a leading expand toggle and a full-width row under it. Client components only. |
expandedKeys | (string | number)[] | — | Controlled expanded row keys. |
defaultExpandedKeys | (string | number)[] | — | Initially expanded row keys (uncontrolled). |
onExpandedChange | (keys: (string | number)[]) => void | — | |
className | string | — |