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
"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.
| Type | Notes | ||
|---|---|---|---|
data | T[] | Yes | – |
columns | ColumnDef<T, any>[] | Yes | – |
searchPlaceholder | string | No | Show a search box that filters across every column. |
selectable | boolean | No | Adds a checkbox column. |
bulkActions | (rows: T[]) => React.ReactNode | No | Rendered in the toolbar while rows are selected. |
onSelectionChange | (rows: T[]) => void | No | – |
pageSize | number | No | Rows per page. 0 turns paging off. Default 10. |
columnToggle | boolean | No | Adds a columns menu for hiding and showing columns. |
getRowId | (row: T, index: number) => string | No | Stable row ids; defaults to the index. |
onRowClick | (row: T) => void | No | – |
density | "compact" | "comfortable" | No | – |
empty | React.ReactNode | No | – |
label | string | No | What the rows are, for the table's accessible name: "Invoices". |
className | string | No | – |
loading | boolean | No | Draws skeleton rows in the table's own shape. |
error | React.ReactNode | No | Replaces the rows with a failure message. |
onRetry | () => void | No | Shown as Retry under `error`. |
variant | "default" | "striped" | "bordered" | No | Row treatment. Default `default`. |
tabs | { value: string; label: string; count?: number }[] | No | Status tabs above the table, with counts. You filter `data` for the chosen one. |
tab | string | No | – |
onTabChange | (value: string) => void | No | – |
actions | React.ReactNode | No | Extra controls at the end of the toolbar: Export, Create. |
renderExpanded | (row: T) => React.ReactNode | No | Makes rows expandable; returns what shows under an open row. |
stickyHeader | boolean | No | Keep the header in view while the body scrolls. Pair with `maxHeight`. |
maxHeight | number | No | Height of the scrolling body, in px. |
initialSorting | SortingState | No | Sorted on first render. |
rowClassName | (row: T) => string | undefined | No | Extra classes for a row, e.g. to mark the viewer's own row. |
Dependencies
npm packages
@tanstack/react-tableclsxlucide-reacttailwind-mergeLiro foundations, installed alongside it
liro-themebuttoncheckboxdropdown-menuinputpaginationstateAccessibility
- 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