Components
Data Table
NativeA table with search, column filters, sorting, pagination, row selection and a column menu. Works on rows in memory or on one server page at a time.
| Plan | Status | City | |||
|---|---|---|---|---|---|
| Harbor Coffee Roasters | Team | Active | Portland | $240 | |
| Northwind Logistics | Business | Active | Rotterdam | $980 | |
| Lumen Dental | Starter | Trial | Leeds | $0 | |
| Fieldnote Studio | Team | Past due | Austin | $240 | |
| Olive & Rye | Starter | Active | Lisbon | $49 |
Showing 1 to 5 of 12 results
12 results.
Installation
npx nook-ui@latest add data-tablePrompt
Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.
Short. For assistants that can run commands in your project.
Add the Nook "Data Table" component to this project, exactly as Nook ships it.
A table with search, column filters, sorting, pagination, row selection and a column menu. Works on rows in memory or on one server page at a time.
Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add data-table`. It writes `components/ui/data-table.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/data-table.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:
```tsx
"use client";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
type Customer = { id: string; name: string; plan: string; status: string; mrr: number; city: string };
const CUSTOMERS: Customer[] = [
{ id: "c1", name: "Harbor Coffee Roasters", plan: "Team", status: "Active", mrr: 240, city: "Portland" },
{ id: "c2", name: "Northwind Logistics", plan: "Business", status: "Active", mrr: 980, city: "Rotterdam" },
{ id: "c3", name: "Lumen Dental", plan: "Starter", status: "Trial", mrr: 0, city: "Leeds" },
{ id: "c4", name: "Fieldnote Studio", plan: "Team", status: "Past due", mrr: 240, city: "Austin" },
{ id: "c5", name: "Olive & Rye", plan: "Starter", status: "Active", mrr: 49, city: "Lisbon" },
{ id: "c6", name: "Kestrel Aerospace", plan: "Business", status: "Active", mrr: 1450, city: "Toulouse" },
{ id: "c7", name: "Paper Kite Books", plan: "Starter", status: "Canceled", mrr: 0, city: "Melbourne" },
{ id: "c8", name: "Tidewater Surf Co", plan: "Team", status: "Trial", mrr: 0, city: "San Diego" },
{ id: "c9", name: "Brightside Pharmacy", plan: "Business", status: "Past due", mrr: 620, city: "Dublin" },
{ id: "c10", name: "Mosaic Learning", plan: "Team", status: "Active", mrr: 240, city: "Toronto" },
{ id: "c11", name: "Quarry Hill Farm", plan: "Starter", status: "Active", mrr: 49, city: "Vermont" },
{ id: "c12", name: "Atlas Bike Repair", plan: "Starter", status: "Trial", mrr: 0, city: "Denver" },
];
const columns: DataTableColumn<Customer>[] = [
{ id: "name", header: "Customer", accessor: (r) => r.name, sortable: true },
{ id: "plan", header: "Plan", accessor: (r) => r.plan, filter: {} },
{
id: "status",
header: "Status",
accessor: (r) => r.status,
filter: {},
cell: (r) => <Badge variant={r.status === "Past due" ? "destructive" : r.status === "Active" ? "default" : "secondary"}>{r.status}</Badge>,
},
{ id: "city", header: "City", accessor: (r) => r.city },
{ id: "mrr", header: "Monthly revenue", accessor: (r) => r.mrr, sortable: true, align: "right", cell: (r) => `$${r.mrr.toLocaleString("en-US")}` },
];
export default function DataTableDefault() {
return (
<DataTable
caption="Customers"
columns={columns}
data={CUSTOMERS}
getRowId={(r) => r.id}
searchPlaceholder="Search customers"
defaultPageSize={5}
pageSizeOptions={[5, 10]}
selectable
columnToggle
bulkActions={(ids) => <Button size="sm" variant="outline">Email {ids.length} customers</Button>}
/>
);
}
```
API
- `DataTable`: The table with its toolbar and pagination. Every piece of state can be controlled.
- `columns` (`DataTableColumn<T>[]`): Column id, header, accessor, optional cell, sortable, filter, align.
- `data` (`T[]`): The rows.
- `getRowId` (`(row: T) => string`): A stable id for each row.
- `caption` (`string`): Names the table for screen readers.
- `selectable` (`boolean`): Adds a checkbox to every row.
- `bulkActions` (`(ids: string[]) => ReactNode`): Buttons shown when rows are selected.
- `columnToggle` (`boolean`): Adds a Columns menu.
- `manual` (`boolean`): Rows come from a server. Pass the current page as data and the result count as total.
Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: A real table with a caption. Sort buttons name the column and set aria-sort. Every row checkbox is named, toolbar controls have labels, and result counts are announced in a status region.
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
"use client";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
type Customer = { id: string; name: string; plan: string; status: string; mrr: number; city: string };
const CUSTOMERS: Customer[] = [
{ id: "c1", name: "Harbor Coffee Roasters", plan: "Team", status: "Active", mrr: 240, city: "Portland" },
{ id: "c2", name: "Northwind Logistics", plan: "Business", status: "Active", mrr: 980, city: "Rotterdam" },
{ id: "c3", name: "Lumen Dental", plan: "Starter", status: "Trial", mrr: 0, city: "Leeds" },
{ id: "c4", name: "Fieldnote Studio", plan: "Team", status: "Past due", mrr: 240, city: "Austin" },
{ id: "c5", name: "Olive & Rye", plan: "Starter", status: "Active", mrr: 49, city: "Lisbon" },
{ id: "c6", name: "Kestrel Aerospace", plan: "Business", status: "Active", mrr: 1450, city: "Toulouse" },
{ id: "c7", name: "Paper Kite Books", plan: "Starter", status: "Canceled", mrr: 0, city: "Melbourne" },
{ id: "c8", name: "Tidewater Surf Co", plan: "Team", status: "Trial", mrr: 0, city: "San Diego" },
{ id: "c9", name: "Brightside Pharmacy", plan: "Business", status: "Past due", mrr: 620, city: "Dublin" },
{ id: "c10", name: "Mosaic Learning", plan: "Team", status: "Active", mrr: 240, city: "Toronto" },
{ id: "c11", name: "Quarry Hill Farm", plan: "Starter", status: "Active", mrr: 49, city: "Vermont" },
{ id: "c12", name: "Atlas Bike Repair", plan: "Starter", status: "Trial", mrr: 0, city: "Denver" },
];
const columns: DataTableColumn<Customer>[] = [
{ id: "name", header: "Customer", accessor: (r) => r.name, sortable: true },
{ id: "plan", header: "Plan", accessor: (r) => r.plan, filter: {} },
{
id: "status",
header: "Status",
accessor: (r) => r.status,
filter: {},
cell: (r) => <Badge variant={r.status === "Past due" ? "destructive" : r.status === "Active" ? "default" : "secondary"}>{r.status}</Badge>,
},
{ id: "city", header: "City", accessor: (r) => r.city },
{ id: "mrr", header: "Monthly revenue", accessor: (r) => r.mrr, sortable: true, align: "right", cell: (r) => `$${r.mrr.toLocaleString("en-US")}` },
];
export default function DataTableDefault() {
return (
<DataTable
caption="Customers"
columns={columns}
data={CUSTOMERS}
getRowId={(r) => r.id}
searchPlaceholder="Search customers"
defaultPageSize={5}
pageSizeOptions={[5, 10]}
selectable
columnToggle
bulkActions={(ids) => <Button size="sm" variant="outline">Email {ids.length} customers</Button>}
/>
);
}Props
DataTable
The table with its toolbar and pagination. Every piece of state can be controlled.
| Prop | Type | Default | Description |
|---|---|---|---|
| columns | DataTableColumn<T>[] | – | Column id, header, accessor, optional cell, sortable, filter, align. |
| data | T[] | – | The rows. |
| getRowId | (row: T) => string | – | A stable id for each row. |
| caption | string | – | Names the table for screen readers. |
| selectable | boolean | – | Adds a checkbox to every row. |
| bulkActions | (ids: string[]) => ReactNode | – | Buttons shown when rows are selected. |
| columnToggle | boolean | – | Adds a Columns menu. |
| manual | boolean | – | Rows come from a server. Pass the current page as data and the result count as total. |
Accessibility
A real table with a caption. Sort buttons name the column and set aria-sort. Every row checkbox is named, toolbar controls have labels, and result counts are announced in a status region.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.