Data Table

TanStack table with sorting, search, row selection, bulk actions, column toggle and pagination.

Category
Data & feedback
Access
Free with an account
Source
499 lines · one file
Added
4 Oct 2026

The decision inside it

Empty is not an error

A search with no matches says what was searched and offers 'Show everything', instead of a blank grid that looks broken.

When to use it

Use Data Table for records people scan, search and act on: invoices, users, orders, logs. Define columns once with TanStack's ColumnDef and pass your rows; sorting, search, selection, column visibility and pagination come with it. When people need to edit cells in place, use Editable Table instead.

Installation

How you get it

Paste this into Claude Code, Cursor, Codex or any coding agent. It installs the file and uses it as it is, instead of writing a new one.

Use Liro's Data Table for this.
Install it: npx shadcn@latest add @liro/data-table
(the @liro registry is set up in components.json, with LIRO_KEY in .env.local)
Import it from @/components/ui/data-table.
Do not rewrite or restyle it. Pass my data through its props
and keep its built-in states.

For the full brief with every prop and the mistakes assistants usually make, use Copy prompt above. Free components install through the @liro registry with your CLI token: see the Namespaced tab.

Usage

components/invoices-table.tsx
"use client";

import { DataTable, type ColumnDef } from "@/components/ui/data-table";

type Invoice = { id: string; customer: string; amount: number; status: "paid" | "open" };

const columns: ColumnDef<Invoice>[] = [
  { accessorKey: "id", header: "Invoice" },
  { accessorKey: "customer", header: "Customer" },
  { accessorKey: "amount", header: "Amount", cell: ({ row }) => `$${row.original.amount.toFixed(2)}` },
  { accessorKey: "status", header: "Status" },
];

export function InvoicesTable({ invoices }: { invoices: Invoice[] }) {
  return (
    <DataTable
      label="Invoices"
      data={invoices}
      columns={columns}
      searchPlaceholder="Search invoices"
      selectable
      pageSize={10}
    />
  );
}

API reference

“Copy prompt” above puts a full brief on your clipboard, install command, dependencies, props, and the mistakes an assistant usually makes with this component.

Props

Read from the component’s own TypeScript interface when the site is built, so this table cannot drift from the file you install.

TypeNotes
dataT[] Yes–
columnsColumnDef<T, any>[] Yes–
searchPlaceholderstring NoShow a search box that filters across every column.
selectableboolean NoAdds a checkbox column.
bulkActions(rows: T[]) => React.ReactNode NoRendered in the toolbar while rows are selected.
onSelectionChange(rows: T[]) => void No–
pageSizenumber NoRows per page. 0 turns paging off. Default 10.
columnToggleboolean NoAdds a columns menu for hiding and showing columns.
getRowId(row: T, index: number) => string NoStable row ids; defaults to the index.
onRowClick(row: T) => void No–
density"compact" | "comfortable" No–
emptyReact.ReactNode No–
labelstring NoWhat the rows are, for the table's accessible name: "Invoices".
classNamestring No–
loadingboolean NoDraws skeleton rows in the table's own shape.
errorReact.ReactNode NoReplaces the rows with a failure message.
onRetry() => void NoShown as Retry under `error`.
variant"default" | "striped" | "bordered" NoRow treatment. Default `default`.
tabs{ value: string; label: string; count?: number }[] NoStatus tabs above the table, with counts. You filter `data` for the chosen one.
tabstring No–
onTabChange(value: string) => void No–
actionsReact.ReactNode NoExtra controls at the end of the toolbar: Export, Create.
renderExpanded(row: T) => React.ReactNode NoMakes rows expandable; returns what shows under an open row.
stickyHeaderboolean NoKeep the header in view while the body scrolls. Pair with `maxHeight`.
maxHeightnumber NoHeight of the scrolling body, in px.
initialSortingSortingState NoSorted on first render.
rowClassName(row: T) => string | undefined NoExtra classes for a row, e.g. to mark the viewer's own row.

Dependencies

npm packages

@tanstack/react-tableclsxlucide-reacttailwind-merge

Liro foundations, installed alongside it

liro-themebuttoncheckboxdropdown-menuinputpaginationstate

Accessibility

  • Keyboard reachable throughout, in visual order
  • Focus trapped in overlays, Escape closes them
  • Focus returns to whatever opened it
  • Live regions announce what changed, not that something did
  • Honours prefers-reduced-motion

Responsive behavior

  • Sizes to its container, not the viewport
  • Usable from 320px up
  • Pointer-based interaction, so trackpad and touch both work
  • No hover-only affordances