Quick start
A minimal table is two pieces: columns (standard TanStack ColumnDefs) and a call to useDataTable, whose result you hand to <DataTable />.
"use client"
import * as React from "react"
import type { ColumnDef } from "@tanstack/react-table"
import { DataTable, useDataTable } from "@/components/ui/data-table"
type Person = { id: string; name: string; email: string; age: number }
const data: Person[] = [
{ id: "1", name: "Ada Lovelace", email: "ada@example.com", age: 36 },
{ id: "2", name: "Alan Turing", email: "alan@example.com", age: 41 },
{ id: "3", name: "Grace Hopper", email: "grace@example.com", age: 85 },
]
const columns: ColumnDef<Person>[] = [
{ accessorKey: "name", header: "Name" },
{ accessorKey: "email", header: "Email" },
{ accessorKey: "age", header: "Age", meta: { align: "right" } },
]
export function PeopleTable() {
const table = useDataTable({
data,
columns,
getRowId: (row) => row.id,
initialState: { pagination: { pageSize: 10 } },
})
return <DataTable table={table} />
}
That already gives you sorting, client pagination, a toolbar with global search, column visibility, and density controls:
Basic
ID | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Ava | Thompson | Owner | Engineering | active | 22 | $45,000 | Jan 2, 2023 | 0% | ||
| Liam | Nguyen | Admin | Marketing | inactive | 25 | $47,137 | Jan 13, 2023 | 9% | ||
| Noah | Silva | Editor | Design | pending | 28 | $49,274 | Jan 24, 2023 | 18% | ||
| Emma | Carter | Viewer | Sales | active | 31 | $51,411 | Feb 4, 2023 | 27% | ||
| Olivia | Rossi | Owner | Support | inactive | 34 | $53,548 | Feb 15, 2023 | 36% | ||
| William | Walker | Admin | Engineering | pending | 37 | $55,685 | Feb 26, 2023 | 45% | ||
| Sophia | Patel | Editor | Marketing | active | 40 | $57,822 | Mar 9, 2023 | 54% | ||
| James | Muller | Viewer | Design | inactive | 43 | $59,959 | Mar 20, 2023 | 63% | ||
| Isabella | Park | Owner | Sales | pending | 46 | $62,096 | Mar 31, 2023 | 72% | ||
| Lucas | Reyes | Admin | Support | active | 49 | $64,233 | Apr 11, 2023 | 81% | ||
| $4,120,536 |
Rows per page
1–10 of 48
Turning features on
Every feature is an option on useDataTable. Flip a flag to enable it — for example, multi-column sorting, per-column filters, and row selection:
const table = useDataTable({
data,
columns,
getRowId: (row) => row.id,
enableMultiSort: true,
defaultShowColumnFilters: true,
enableRowSelection: true,
})
Memoize data and columns
Pass stable references for data and columns (e.g. via React.useMemo or module scope). Handing TanStack a new columns identity every render can reset state.
Where to go next
- Usage — the options-in / instance-out model and
table.cnTable. - Guides — enable each feature, with live examples.
- API reference — every option and its default.