A table for real data, with sorting, search, row selection, pinned columns, a sticky header and pagination.
Install
Add it to your project
Run this in a project set up for shadcn/ui. It writes the files and installs the npm packages.
First time: connect the Infinity UI registry
- Create a personal token on your Tokens page.
- Put it in
.env.localasINFINITYUI_TOKEN. - Add the registry to
components.json:
{
"registries": {
"@infinityui": {
"url": "https://infinityui.io/r/{name}.json",
"headers": {
"Authorization": "Bearer ${INFINITYUI_TOKEN}"
}
}
}
}Using Claude Code, Codex, Cursor, Lovable or v0? See CLI & MCP for a setup prompt.
npm packages it adds
- cn
- @base-ui/react
- @tabler/icons-react
- @tanstack/react-table
Code
"use client"
import { Badge, BadgeDot } from "@/components/ui/badge"
import {
createDataTableColumns,
DataTable,
DataTableColumnHeader,
DataTableContent,
DataTablePagination,
DataTableSearch,
DataTableSelectAll,
DataTableSelectRow,
DataTableToolbar,
DataTableViewOptions,
useDataTable,
} from "@/components/ui/data-table"
type Payment = {
id: string
email: string
status: "paid" | "pending" | "failed"
amount: number
method: string
country: string
date: string
}
const statuses = ["paid", "pending", "failed"] as const
const methods = ["Card", "PayPal", "Bank", "Apple Pay"]
const countries = ["United States", "Germany", "India", "Japan", "Brazil"]
const names = ["olivia", "jackson", "isabella", "william", "sofia", "liam"]
function makePayments(count: number): Payment[] {
return Array.from({ length: count }, (_, index) => ({
id: `pay_${String(index + 1).padStart(4, "0")}`,
email: `${names[index % names.length]}.${Math.floor(index / names.length) + 1}@example.com`,
status: statuses[(index * 7) % 3],
amount: Math.round(((index * 7919) % 100000) / 10) / 10 + 5,
method: methods[index % methods.length],
country: countries[(index * 3) % countries.length],
date: `2026-${String((index % 9) + 1).padStart(2, "0")}-${String((index % 27) + 1).padStart(2, "0")}`,
}))
}
const payments = makePayments(42)
const currency = new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
})
const statusVariant = {
paid: "success",
pending: "warning",
failed: "destructive",
} as const
const helper = createDataTableColumns<Payment>()
const columns = helper.columns([
helper.display({
id: "select",
header: ({ table }) => <DataTableSelectAll table={table} />,
cell: ({ row }) => <DataTableSelectRow row={row} />,
enableSorting: false,
enableHiding: false,
}),
helper.accessor("email", {
header: ({ column }) => (
<DataTableColumnHeader column={column} title="Email" />
),
}),
helper.accessor("status", {
header: ({ column }) => (
<DataTableColumnHeader column={column} title="Status" />
),
cell: ({ getValue }) => {
const status = getValue()
return (
<Badge variant={statusVariant[status]}>
<BadgeDot />
<span className="capitalize">{status}</span>
</Badge>
)
},
}),
helper.accessor("method", { header: "Method" }),
helper.accessor("country", { header: "Country" }),
helper.accessor("date", {
header: ({ column }) => (
<DataTableColumnHeader column={column} title="Date" />
),
}),
helper.accessor("amount", {
header: ({ column }) => (
<DataTableColumnHeader column={column} title="Amount" />
),
cell: ({ getValue }) => currency.format(getValue()),
meta: { align: "end" },
}),
])
export function DataTableDemo() {
const table = useDataTable({
data: payments,
columns,
getRowId: (row) => row.id,
})
return (
<DataTable table={table}>
<DataTableToolbar>
<DataTableSearch placeholder="Search payments…" />
<DataTableViewOptions />
</DataTableToolbar>
<DataTableContent emptyMessage="No payments match your search." />
<DataTablePagination />
</DataTable>
)
}
































