Data Table
Sorting, search, column visibility, selection and paging.
Installation
$ pnpm dlx shadcn@latest add @synccn/data-tableFirst time in this project? Connect synccn with one command.
Usage
import { DataTable } from "@/components/ui/data-table";<DataTable columns={columns} data={rows} />API reference
Generated from the component's TypeScript types, so it always matches the code.
DataTable
Sorting, global search, column visibility, row selection and pagination. columns: [{ key, header, cell?(row), sortable?, align?, hideable? }]
- columnsrequired
DataTableColumn<T>[]Column definitions.
- datarequired
T[]Rows.
- pageSize
numberDefault
5Rows per page.
- searchKeys
(keyof T & string)[]Fields the search box matches. Defaults to every column.
- rowKey
keyof T & stringDefault
"id"Field that uniquely identifies a row.
- toolbar
React.ReactNodeExtra controls next to the Columns menu.
- className
stringExtra classes for the root element.
Dependencies
Read from the component's imports when the site builds. The CLI installs all of these for you.
Components
- Checkbox for
Checkbox - Input for
Input - Dropdown Menu for
DropdownMenu - Pagination for
Pagination - Table for
Table,TableBody,TableCell,TableHead,TableHeader,TableRow
Helpers
- lib/utilscn (merges class names)
npm packages
- clsx for cn()
- tailwind-merge for cn()
- lucide-react for ArrowDown, ArrowUp, ChevronsUpDown, Search, SlidersHorizontal
Accessibility
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA attributes: aria-label, aria-sort