UI
DataTable
Sortable, paginated data tables powered by @tanstack/react-table.
Preview
| IDโ | Nameโ | Roleโ | Statusโ | |
|---|---|---|---|---|
| 1 | Alice Johnson | alice@example.com | Admin | Active |
| 2 | Bob Smith | bob@example.com | Editor | Active |
| 3 | Carol White | carol@example.com | Viewer | Inactive |
| 4 | David Lee | david@example.com | Editor | Active |
| 5 | Eva Martinez | eva@example.com | Admin | Active |
Page 1 of 2 ยท 8 rows
Installation
npm install @tanstack/react-table
Usage
import { createColumnHelper } from '@tanstack/react-table'import { DataTable } from '@/components/ui/DataTable'interface User { id: number; name: string; email: string; role: string }const columnHelper = createColumnHelper<User>()const columns = [columnHelper.accessor('id', { header: 'ID' }),columnHelper.accessor('name', { header: 'Name' }),columnHelper.accessor('email', { header: 'Email', enableSorting: false }),columnHelper.accessor('role', { header: 'Role' }),]const data: User[] = [{ id: 1, name: 'Alice Johnson', email: 'alice@example.com', role: 'Admin' },// ...]export default function Page() {return <DataTable columns={columns} data={data} pageSize={5} />}
Variants
Striped & Bordered
| IDโ | Nameโ | Roleโ | Statusโ | |
|---|---|---|---|---|
| 1 | Alice Johnson | alice@example.com | Admin | Active |
| 2 | Bob Smith | bob@example.com | Editor | Active |
| 3 | Carol White | carol@example.com | Viewer | Inactive |
| 4 | David Lee | david@example.com | Editor | Active |
| 5 | Eva Martinez | eva@example.com | Admin | Active |
Page 1 of 2 ยท 8 rows
Compact (no pagination)
| IDโ | Nameโ | Roleโ | Statusโ | |
|---|---|---|---|---|
| 1 | Alice Johnson | alice@example.com | Admin | Active |
| 2 | Bob Smith | bob@example.com | Editor | Active |
| 3 | Carol White | carol@example.com | Viewer | Inactive |
| 4 | David Lee | david@example.com | Editor | Active |
Prompt Preview
Copy a prompt that recreates this UI
Paste this into your AI coding assistant to generate code that closely matches the reference, including color, size, shape, typography, spacing, and polish.
Copy-ready AI prompt
Starts from the current visual reference and project constraints.
Tweak only product-specific copy or data after the first generation pass.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
columns* | ColumnDef<TData>[] | - | Column definitions from @tanstack/react-table |
data* | TData[] | - | Array of row data objects |
pageSize | number | 10 | Number of rows per page |
showPagination | boolean | true | Show pagination controls |
striped | boolean | false | Alternate row background colors |
bordered | boolean | false | Add border around the table |
compact | boolean | false | Reduce cell padding for dense display |
className | string | - | Extra CSS classes for the wrapper |