Data Table

A full list screen on TanStack Table: frozen ID and action columns, sticky header, sort on every column, search and faceted filters, selection with bulk actions, paging, column choice, URL state and honest loading, empty and error states.

View as Markdown

Click a row (or press Enter) to open it; the breadcrumb leads back. Sort, search, filters and page are written to the URL (?plots.sort=yield.desc), so a view can be shared.

Actions
P-015River plot 2RiceGoatRipe2 tiles2026-11-15718
P-029Well plot 4RicePigRipe2 tiles2026-11-01716
P-005Well plot 1PeanutsPigGrowing7 tiles2026-11-17628
P-019Pond plot 3PeanutsRoosterGrowing7 tiles2026-11-03626
P-014Temple plot 2Luffa gourdDogWilted6 tiles2026-11-04581
P-028Bamboo plot 4Luffa gourdMonkeyWilted6 tiles2026-11-18579
P-009North plot 2CornOxRipe5 tiles2026-11-05536
P-023River plot 3CornGoatRipe5 tiles2026-11-19534
P-004Bamboo plot 1Sweet potatoMonkeyGrowing4 tiles2026-11-06491
P-018East plot 3Sweet potatoRatGrowing4 tiles2026-11-20489
1–10 of 32
Page 1 of 4

Installation

npx shadcn@latest add @cozy/data-table

Usage

import { DataTable, DataTableColumnHeader, IconAction, facetFilter } from "@/components/ui/data-table"

const columns: ColumnDef<Plot>[] = [
  { accessorKey: "id", size: 96, header: ({ column }) => <DataTableColumnHeader column={column} title="ID" /> },
  { accessorKey: "status", filterFn: facetFilter, header: ({ column }) => <DataTableColumnHeader column={column} title="Status" /> },
  { accessorKey: "yield", meta: { align: "end" }, header: ({ column }) => <DataTableColumnHeader column={column} title="Yield" /> },
  { id: "actions", size: 104, cell: ({ row }) => <IconAction label="Open" onClick={() => open(row.original)}><OpenGlyph /></IconAction> },
]

<DataTable
  label="Plots"
  columns={columns}
  data={plots}
  pin={{ left: ["id"], right: ["actions"] }}
  facets={[{ column: "status", title: "Status" }]}
  urlKey="plots"
  onRowClick={open}
  bulkActions={(rows, clear) => <IconAction label="Harvest selected" onClick={clear}><RiceGlyph /></IconAction>}
/>

Table rules this component follows: full width; ID or name frozen left and actions frozen right, only the middle scrolls (on narrow screens only the first left column stays frozen); sticky header; 12 px grey sentence-case headers with no band and no zebra rows; every column sorts, with the arrow on the active column only; search plus one faceted filter per fixed-value column, Reset and the row count; numbers and dates right-aligned; a row opens its detail screen, which has a breadcrumb back; sort and filters live in the URL; every action is an icon button with a tooltip and an accessible name; loading, empty and error states keep the frame.

Examples

States

Loading draws bars at the real cell sizes; empty and error keep the frame, say what happened and offer the next step.

1–5 of 5
Page 1 of 1

API

Everything else is passed through to the underlying element or Radix primitive.

PropTypeDefaultDescription
labelstring–Accessible name of the table; also used in the search label.
columns / dataColumnDef<T>[] / T[]–TanStack Table v8 columns and rows. `meta: { title, align: "end", skeleton }` per column.
pin{ left?: string[]; right?: string[] }–Columns frozen to the edges (ID/name left, actions right). The middle scrolls.
facets{ column; title; options? }[]–One faceted filter per fixed-value column, with counts. Give the column `filterFn: facetFilter`.
bulkActions(rows, clear) => ReactNode–Turns on selection; shown in a bar inside the board when rows are selected.
onRowClick(row: T) => void–Opens the item. Clicks on controls inside the row are ignored; Enter works too.
urlKeystring–Mirror search, sort, filters, page and size in the query string under this prefix.
status"ready" | "loading" | "error""ready"With `errorText`, `lastGood` and `onRetry` for errors; `empty` replaces the empty message.
pageSizesnumber[][10, 20, 50]Choices in Rows per page; the first is the default.
maxHeightnumber | string560Height of the scrolling body; the header sticks inside it.