Primitives
Data Table
A data table built on top of the Table primitive with client-side sorting, text filtering, row selection, column visibility, and pagination, using plain React state.
Data Table Examples
| success | ken99@example.com | $316.00 | |
| pending | abe45@example.com | $242.00 | |
| processing | monserrat44@example.com | $837.00 | |
| success | silas22@example.com | $874.00 | |
| failed | carmella@example.com | $721.00 |
0 of 10 row(s) selected.
Page 1 of 2
Installation
# The data table is composed from existing primitives, already installed at:
# src/components/ui/shadcn/table.tsx
# src/components/ui/shadcn/checkbox.tsx
# src/components/ui/shadcn/dropdown-menu.tsx
Usage
'use client'
import * as React from 'react'
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/shadcn/table'
type Payment = { id: string; email: string; amount: number }
export function DataTableDemo({ data }: { data: Payment[] }) {
const [filter, setFilter] = React.useState('')
const filtered = data.filter((row) =>
row.email.toLowerCase().includes(filter.toLowerCase())
)
return (
<Table>
<TableHeader>
<TableRow>
<TableHead>Email</TableHead>
<TableHead className="text-right">Amount</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{filtered.map((row) => (
<TableRow key={row.id}>
<TableCell>{row.email}</TableCell>
<TableCell className="text-right">{row.amount}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
)
}
Components
| Component | Description |
|---|---|
| Table | The root table element with responsive overflow |
| TableHeader / TableBody | Groups header and body rows |
| TableRow | A single row, supports data-state="selected" |
| TableHead / TableCell | Header and body cells |
| Checkbox | Used for row and select-all selection |
| DropdownMenu | Used to build the column visibility toggle |