A real table with multi-column sort, search and filters, range selection, column visibility and density, paged or virtualised for thousands of rows.
Used for
- Run history
- Ticket lists
- Eval results
- Usage by model
- Audit logs
Examples
Installation
npx knowns-ui@latest add data-tableFor Claude Code, Cursor or Codex: installs it and wires the props to your own data.
Paste this into your coding agent (Claude Code, Cursor, Codex). It checks your project, sets up the registry, runs the install and verifies it.
Install prompt
Install Data table from Knowns UI into this project. Work step by step, show me each change, and ask before you edit files outside this project.
Context: Knowns UI (https://ui.knowns.dev) is a shadcn registry. Items land in the project as source files. Docs: https://ui.knowns.dev/docs/data-table
1. Check the project first. Stop and tell me if any of these is missing:
- React 19 and Tailwind CSS v4.
- A components.json at the project root. If there is none, ask me before running `npx knowns-ui@latest init --no-key` (it runs shadcn init when needed, then adds the registries).
2. Run:
```bash
npx knowns-ui@latest add data-table
```
It writes these files:
- lib/knowns/run.ts
- lib/knowns/json.tsx
- lib/knowns/status.ts
- lib/knowns/tone.ts
- lib/knowns/types.ts
- lib/knowns/use-abortable.ts
- lib/knowns/utils.ts
- components/ui/knowns/spinner.tsx
- components/ui/knowns/button.tsx
- lib/knowns/motion.tsx
- lib/knowns/motion-utils.ts
- components/ui/knowns/calendar/calendar.tsx
- components/ui/knowns/calendar/calendar-utils.ts
- components/ui/knowns/calendar/calendar-zone.ts
- components/ui/knowns/checkbox.tsx
- components/ui/knowns/field-class.ts
- components/ui/knowns/use-floating.ts
- components/ui/knowns/popover.tsx
- components/ui/knowns/date-range-picker.tsx
- components/ui/knowns/kbd.tsx
- components/ui/knowns/textarea.tsx
- components/ui/knowns/chat-composer/use-autosize.ts
- components/ui/knowns/tooltip.tsx
- components/ui/knowns/tooltip-utils.ts
- components/ui/knowns/input.tsx
- components/ui/knowns/menu.tsx
- components/ui/knowns/segmented-control.tsx
- components/ui/knowns/skeleton.tsx
- components/ui/knowns/slider.tsx
- components/ui/knowns/data-table/data-table.tsx
- components/ui/knowns/data-table/data-table-action-bar.tsx
- components/ui/knowns/data-table/data-table-filters.tsx
- components/ui/knowns/data-table/table-filters.ts
- components/ui/knowns/data-table/table-utils.ts
and installs these npm packages: clsx@^2.1.1, tailwind-merge@^3.7.0, class-variance-authority@^0.7.1.
3. While it runs:
- It also adds a few @keyframes (all named kn-*) to the global CSS file (globals.css or the file components.json points at). Let it: they only add animations.
- If it asks to overwrite files under lib/knowns/: these are shared by every Knowns UI item. List them, say whether I changed them (check git), and ask me before you answer.
- If it asks to overwrite any other file, show me the diff and ask me.
4. Verify:
- Every file in the list above exists.
- The project type-checks (for example `npx tsc --noEmit`) and the dev build has no new errors.
5. Use it: follow the examples and props on https://ui.knowns.dev/docs/data-table, and ask me if anything about my data is unclear.
If the Knowns UI MCP server is connected (https://ui.knowns.dev/docs/ai-and-mcp), use get_component({ name: "data-table" }) or search_docs for details.
Finish with a short summary: the files you added or changed, the packages you installed, and anything I still need to do.Props
- title / titleAs
ReactNode / "h2"|"h3"|"h4"|"div"- Default
- / "h3" - Toolbar title and its tag. Pick the level that follows the page's headings, or div for a name only.
- rows / columns / getRowId
T[] / DataColumn<T>[] / (row) => string- Column: { id, header, accessor? (key or fn), cell?, align?, width?, sortable?, compare?, filterable?, searchable?, hideable?, defaultHidden?, label? }. The accessor feeds sort, search and filters.
- sort / defaultSort / onSortChange
{ id, desc }[]- Default
[] - Header click: ascending → descending → off. Shift-click adds a rule (multi-sort; the rank shows as a small number). Natural order (“Agent 2” before “Agent 10”); empty values last. aria-sort on headers.
- selectable / selected / defaultSelected / onSelectedChange
boolean / string[]- Default
false - Checkbox column. Shift-click selects or clears the range from the last clicked row, in display order. The header box selects the shown rows (mixed when some are).
- search / filterRow
boolean- Default
true / false - Toolbar search across searchable columns; a row of per-column filter fields under the sticky header.
- filterBar / filters / defaultFilters / onFiltersChange
boolean / FilterState- Default
false - A bar of filter chips, one per column with a `variant`. State is one plain object keyed by column id: { kind: "select", values } | { kind: "range", min, max } | { kind: "date", from, to } | { kind: "text", value }. Controlled or not.
- column variant / options / formatFilter
"text"|"select"|"range"|"date" / { value, label? }[] / (n) => string- What chip the column gets. A select lists its values with how many rows carry each (counted with the other filters applied), from `options` or from the data. A range is a slider with two number fields; a date is a calendar range.
- rowFilter
(row) => boolean- One more rule every row must pass, from your own filter UI. It composes with search, the chips and the filter row.
- bulkActions / bulkNoun
({ ids, rows, clear }) => ReactNode / [string, string]- Buttons for the selected rows (needs selectable). The bar rises in with the count and a clear button, Esc clears, and it counts only selected rows still in the filtered list. Also exported alone: DataTableActionBar.
- pageSize / pageSizes
number|false / number[]- Default
25 / [10, 25, 50, 100] - Paging with a rows-per-page select. false: one scrolling list.
- virtualizeAbove / maxHeight
number / px- Default
200 / 480 - With pageSize false, past this many rows only those in view render, with spacer rows; aria-rowcount and aria-rowindex keep the position known.
- density / defaultDensity / onDensityChange
"compact"|"default"|"comfortable"- Default
"default" - Row height 32 / 40 / 48. The toolbar switch shows with controls.
- controls
boolean- Default
true - Density switch and the Columns menu (switch rows; the last visible column can't be hidden).
- loading / empty
boolean / ReactNode- Default
false / - - Skeleton rows with aria-busy; empty text tells “no rows yet” from “no rows match”.
- toolbar / title / onRowClick
ReactNode / ReactNode / (row) => void- Extra toolbar content (e.g. bulk actions for the selection); the title names the region and the table.
- rowClassName
(row) => string|undefined- Extra classes for one row, for example an enter animation on a row that just arrived.
| Prop | Type | Default | Description |
|---|---|---|---|
| title / titleAs | ReactNode / "h2" | "h3" | "h4" | "div" | - / "h3" | Toolbar title and its tag. Pick the level that follows the page's headings, or div for a name only. |
| rows / columns / getRowId | T[] / DataColumn<T>[] / (row) => string | - | Column: { id, header, accessor? (key or fn), cell?, align?, width?, sortable?, compare?, filterable?, searchable?, hideable?, defaultHidden?, label? }. The accessor feeds sort, search and filters. |
| sort / defaultSort / onSortChange | { id, desc }[] | [] | Header click: ascending → descending → off. Shift-click adds a rule (multi-sort; the rank shows as a small number). Natural order (“Agent 2” before “Agent 10”); empty values last. aria-sort on headers. |
| selectable / selected / defaultSelected / onSelectedChange | boolean / string[] | false | Checkbox column. Shift-click selects or clears the range from the last clicked row, in display order. The header box selects the shown rows (mixed when some are). |
| search / filterRow | boolean | true / false | Toolbar search across searchable columns; a row of per-column filter fields under the sticky header. |
| filterBar / filters / defaultFilters / onFiltersChange | boolean / FilterState | false | A bar of filter chips, one per column with a `variant`. State is one plain object keyed by column id: { kind: "select", values } | { kind: "range", min, max } | { kind: "date", from, to } | { kind: "text", value }. Controlled or not. |
| column variant / options / formatFilter | "text" | "select" | "range" | "date" / { value, label? }[] / (n) => string | - | What chip the column gets. A select lists its values with how many rows carry each (counted with the other filters applied), from `options` or from the data. A range is a slider with two number fields; a date is a calendar range. |
| rowFilter | (row) => boolean | - | One more rule every row must pass, from your own filter UI. It composes with search, the chips and the filter row. |
| bulkActions / bulkNoun | ({ ids, rows, clear }) => ReactNode / [string, string] | - | Buttons for the selected rows (needs selectable). The bar rises in with the count and a clear button, Esc clears, and it counts only selected rows still in the filtered list. Also exported alone: DataTableActionBar. |
| pageSize / pageSizes | number | false / number[] | 25 / [10, 25, 50, 100] | Paging with a rows-per-page select. false: one scrolling list. |
| virtualizeAbove / maxHeight | number / px | 200 / 480 | With pageSize false, past this many rows only those in view render, with spacer rows; aria-rowcount and aria-rowindex keep the position known. |
| density / defaultDensity / onDensityChange | "compact" | "default" | "comfortable" | "default" | Row height 32 / 40 / 48. The toolbar switch shows with controls. |
| controls | boolean | true | Density switch and the Columns menu (switch rows; the last visible column can't be hidden). |
| loading / empty | boolean / ReactNode | false / - | Skeleton rows with aria-busy; empty text tells “no rows yet” from “no rows match”. |
| toolbar / title / onRowClick | ReactNode / ReactNode / (row) => void | - | Extra toolbar content (e.g. bulk actions for the selection); the title names the region and the table. |
| rowClassName | (row) => string | undefined | - | Extra classes for one row, for example an enter animation on a row that just arrived. |
What it handles
- 01Renders a real table element with `aria-sort` on headers, and adds `aria-rowcount` and `aria-rowindex` when the rows are virtualised.
- 02Sorts by clicking a header and adds a second rule on Shift-click, using each column's `accessor` or your own `compare` function.
- 03Searches every column marked searchable, and filters with `filterBar`: one chip per column with a `variant`, a select that counts rows per value, a number range, a date range or text, or a `filterRow` of fields.
- 04Selects rows with a checkbox column when `selectable` is set, Shift-click picks a range, and `bulkActions` adds a bar with the count, your buttons, a clear button and Esc.
- 05Pages the rows with `pageSize` and `pageSizes`, or with `pageSize` false it scrolls inside `maxHeight` and only renders the rows in view above `virtualizeAbove`.
- 06Switches density between compact, default and roomy, hides columns from a Columns menu, and shows built-in `loading` and `empty` states.
States
- First render
- Nothing. It paints as it is
- none
- Row hover
- The row background changes colour
- 120ms, ease out
- Selection starts
- The action bar fades in and rises 6px
- 180ms, ease out
- Selection clears
- The action bar fades out and drops 6px
- 120ms, ease out
- Sort, filter or page change
- The rows are replaced at once
- none
- Loading
- Skeleton rows stand in for the body
- none
- Reduced motion
- Nothing extra to stop; the only motion is the colour change
- 0ms
| State | What moves | Timing |
|---|---|---|
| First render | Nothing. It paints as it is | none |
| Row hover | The row background changes colour | 120ms, ease out |
| Selection starts | The action bar fades in and rises 6px | 180ms, ease out |
| Selection clears | The action bar fades out and drops 6px | 120ms, ease out |
| Sort, filter or page change | The rows are replaced at once | none |
| Loading | Skeleton rows stand in for the body | none |
| Reduced motion | Nothing extra to stop; the only motion is the colour change | 0ms |
Works with
- CheckboxInstalled with it. The selection column and the header toggle are checkboxes.
- MenuInstalled with it. The Columns menu hides and shows columns.
- Segmented controlInstalled with it. It switches the density.
- SkeletonInstalled with it. It fills the body while `loading` is true.
- PopoverInstalled with it. Each filter chip opens its panel in one.
- SliderInstalled with it. A range chip uses it for the minimum and maximum.
When to use
When to use
- Rows to sort, filter, search, select and page, or thousands of rows with virtualisation.
When not to use
- A handful of cards or settings: a list reads better: use Card.
Using with AI
Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:
- Add the Knowns UI Data Table to my app and wire it to my own data.
- I need rows to sort, filter, search, select and page, or thousands of rows with virtualisation. Set that up with the Knowns UI Data Table.
- Which Data Table props do I need for a minimal setup? Show me a short example.
With the server connected, your assistant calls get_component({ name: "data-table" }) and search_docs({ query: "data table" }).