Founding price: $35, then $79.99 after 23:59 UTC on 4 November, then $79.99
Get ProThe Table primitive gives you styled, semantic <table> markup. For
sorting, filtering, selection and pagination, pair it with
TanStack Table, a headless library that handles
the logic while you keep full control of the markup.
TanStack Table is not bundled with any component here; you install it in your own project.
"use client"
import * as React from "react"
import {
flexRender,
getCoreRowModel,
getSortedRowModel,
useReactTable,
type ColumnDef,
type SortingState,
} from "@tanstack/react-table"
import { Button } from "@/components/ui/button"
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table"
type Order = { id: string; customer: string; total: number }
const columns: ColumnDef<Order>[] = [
{ accessorKey: "id", header: "Order" },
{ accessorKey: "customer", header: "Customer" },
{
accessorKey: "total",
header: ({ column }) => (
<Button
variant="ghost"
size="sm"
onClick={() => column.toggleSorting()}
aria-label="Sort by total"
>
Total
</Button>
),
cell: ({ getValue }) =>
new Intl.NumberFormat("en", {
style: "currency",
currency: "USD",
}).format(getValue<number>()),
},
]
export function OrdersTable({ data }: { data: Order[] }) {
const [sorting, setSorting] = React.useState<SortingState>([])
const table = useReactTable({
data,
columns,
state: { sorting },
onSortingChange: setSorting,
getCoreRowModel: getCoreRowModel(),
getSortedRowModel: getSortedRowModel(),
})
return (
<Table>
<TableHeader>
{table.getHeaderGroups().map((group) => (
<TableRow key={group.id}>
{group.headers.map((header) => (
<TableHead
key={header.id}
aria-sort={
header.column.getIsSorted() === "asc"
? "ascending"
: header.column.getIsSorted() === "desc"
? "descending"
: undefined
}
>
{flexRender(
header.column.columnDef.header,
header.getContext()
)}
</TableHead>
))}
</TableRow>
))}
</TableHeader>
<TableBody>
{table.getRowModel().rows.length ? (
table.getRowModel().rows.map((row) => (
<TableRow key={row.id}>
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id}>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</TableCell>
))}
</TableRow>
))
) : (
<TableRow>
<TableCell colSpan={columns.length}>No orders yet.</TableCell>
</TableRow>
)}
</TableBody>
</Table>
)
}getFilteredRowModel() and bind an Input to
column.setFilterValue.getPaginationRowModel() and render
table.previousPage() / table.nextPage() buttons.row.getToggleSelectedHandler(), and label each checkbox with the row's
name.<table> markup. Don't rebuild tables from divs.aria-sort on the sorted column header, and make the sort control a
button.aria-label describing what it lists.