Data Table
A table on TanStack Table for data people work with: sort, filter, search, select rows, show and pin columns, page and export, all on the keyboard.
Playground
Installation
Data Table comes with WunderUI Core and Pro, in the package from your plan. See the plans.
Then import what you need:
import {
DataTable,
DataTableBulkContext,
DataTableColumnDef,
DataTableColumnMeta,
DataTableError,
DataTableExpandedState,
DataTableExportContext,
DataTableFilter,
DataTableFilterOption,
DataTableFiltersState,
DataTablePaginationState,
DataTablePinningState,
DataTableProps,
DataTableQuery,
DataTableSelectionState,
DataTableServerSide,
DataTableSortingState,
DataTableState,
DataTableUrlStateOptions,
DataTableVisibilityState,
} from "@wunderui/react"Then use it:
import { DataTable, type DataTableColumnDef } from "@wunderui/react"
type Invoice = { id: string; owner: string; status: "Paid" | "Pending" | "Overdue"; amount: number }
const columns: DataTableColumnDef<Invoice>[] = [
{ accessorKey: "id", header: "Invoice" },
{ accessorKey: "owner", header: "Owner", meta: { filter: { type: "text" } } },
{ accessorKey: "status", header: "Status", meta: { filter: { type: "multiSelect" } } },
{ accessorKey: "amount", header: "Amount", meta: { numeric: true, filter: { type: "number", unit: "USD" } } },
]
// Keep `columns` and `data` stable: module constants, state or useMemo.
const invoices: Invoice[] = [
{ id: "INV-2001", owner: "Nora Lindgren", status: "Paid", amount: 897 },
{ id: "INV-2002", owner: "Daniel Okafor", status: "Pending", amount: 398 },
{ id: "INV-2003", owner: "Priya Raman", status: "Paid", amount: 597 },
]
export function Invoices() {
return <DataTable aria-label="Invoices" columns={columns} data={invoices} getRowId={(row) => row.id} rowLabel={(row) => row.id} />
}Expected result: You see a card with a search field, Filter, View and Export buttons, sortable columns, three invoice rows with checkboxes and a pager. Tick a row and the selection bar appears.
When to use
Use Data Table for
- Rows people work with: sort on several columns, filter, search, select and act on many at once
- Data that lives on a server, paged, sorted and filtered by your API
- A table whose view should survive a reload or a shared link, with a CSV export
Use something else for
- Table for a short list people only read, with the cells of your own markup
- Data Grid for a small table with search, sorting and paging where you do not need to act on the selection
- Filter Menu for one filter control for a list that is not a table
Filters
A column with a filter setting can be filtered. The Filter button lists those columns, and every filter becomes a chip you can edit or remove.
Sorting
Click a header to sort: ascending, descending, off. Shift-click, Shift+Enter or Then by in the column menu adds a column, and a small number shows the order.
Selection
Row checkboxes, shift-click for a range, and a floating bar with your bulk actions, Select all and Export selected. Selection is kept by row id, so it survives paging and sorting.
Columns
The View menu shows and hides columns, and the column menu pins one to the start or end. The checkbox column always stays first, and the last visible column cannot be hidden.
Data source
By default the table pages, sorts and filters the rows you pass. In server mode it tells you what to ask for through a query change handler, and your data and row count are the answer.
States
Loading, empty, no results and error are built in and keep the toolbar and header. Each one says what happened and what to do next.
URL state
The useDataTableUrlState hook keeps page, order, filters and search in the address bar, so a view can be linked and reloaded. It has its own page, and the table takes two props from it.
Keyboard interactions
The table is one grid with one tab stop: Tab enters it once and leaves it once, however many rows there are. The toolbar, chips and pager are ordinary tab stops before and after it.
- TaborShiftTab
- Enters the grid on the last active cell (the first header cell to begin with) and leaves it on the next Tab. Between the toolbar, the chips, the grid and the pager it moves in reading order.
- ArrowRightorArrowLeftorArrowDownorArrowUp
- Moves to the neighbouring cell. At an edge it stays where it is.
- HomeorEnd
- First or last cell of the row.
- CtrlHomeorCtrlEnd
- First or last cell of the grid on this page.
- PageUporPageDown
- Ten rows up or down, or to the first or last row.
- EnterorSpace
- Does the main thing of the cell: sorts the column on a header, ticks the checkbox on a row, opens or closes a row with a chevron. A cell with several controls and no main one moves focus into the cell instead.
- ShiftEnter
- On a header, adds the column to the sort instead of replacing it. A number then shows the order.
- F2
- Moves focus to the first control of the cell, such as the column menu of a header. Tab and Shift+Tab then walk the controls of that cell.
- Esc
- From a control inside a cell, returns focus to the cell. In an open menu or the filter popover it closes the popup and returns focus to its button.
Behavior and motion
What the table does with its state, its rows and its data, and what it leaves to you.
- State
- Each part of the state (sorting, filters, search, columns, selection, paging, pinning, expanded rows) is controlled when you pass its value and change handler, and kept by the table otherwise.
- Page resets
- A new sort, filter or search goes back to the first page. If the current page disappears, the table steps back to the last one, except with server paging where you own the page.
- Query callback
- The query callback fires when the page, order, a filter or the search changes, but not on the first render. It is the one callback to fetch from.
- Selection
- Selection is kept by row id and survives paging and sorting. The header checkbox ticks the page, shift-click ticks a range, and Select all ticks every filtered row (left out with server paging).
- Filters and search
- Search covers the text and number columns. Filters can be text, one choice, several choices or a number range, with choices and counts read from the loaded rows unless you list them.
- Columns
- Columns default to 160 px and the rest of the row is shared. A wide table scrolls inside its box, and columns can be hidden or pinned to either end, but not resized or reordered.
- Server-side data
- With server-side data the table does not sort, filter or page. It reports the query and shows the data and row count you pass, so keep loading on until the answer arrives.
- States
- Loading draws skeleton rows, Empty says there is no data, No results offers Reset filters, and Error offers Try again when a retry handler is set. Export is disabled in all four.
- Announcements
- A hidden status line reads the row count, Loading rows or the error, and the action bar count is a polite live region. The grid also reports row and column counts, selection and sort order.
- Export
- Export writes a CSV of the visible columns in their order, with header labels and a byte order mark so Excel reads UTF-8. Export selected writes only the selected rows.
- Limits
- Every row of the current page is rendered and nothing is virtualised, so for very large data use server-side mode. Inline editing and column resizing are not part of the table.
- Motion
- The action bar fades in and slides up 8 px, and an opened row fades in while its chevron turns. With reduced motion the slide and fades are off and the chevron turns at once.
Anatomy
The figure shows a filtered table with one row selected, so the chip and the action bar appear. The loading, empty and error rows replace the rows and have no number.
| INV-2002 | Daniel Okafor | Core | $398 | ||
| INV-2006 | Nora Lindgren | Core | $597 | ||
| INV-2010 | Maya Kessler | Pro | $299 | ||
| INV-2014 | Tomás Ferreira | Core | $398 |
- data-slot="data-table"
The whole table in one bordered box: a toolbar, filter chips, the grid, an action bar while rows are selected, and a footer. Its state reads ready, loading, empty or error.
A toolbar named Table tools: search on the left, then Filter, View, Export and any actions you pass in. Each control can be turned off.
The field that filters every row by the text of the text and number columns. A new search goes back to the first page.
- data-slot="data-table-filter-trigger"
Opens a list of filterable columns. Choosing one opens its editor: a text field, a list of choices or a minimum and maximum, and the button shows how many filters are active.
- data-slot="data-table-view-trigger"
A menu of checkboxes that shows and hides columns. It never lets the last visible column go.
- data-slot="data-table-export"
Saves every row, after filtering and sorting, as a CSV of the visible columns. It is disabled while loading, on an error and with no rows, and a custom export handler replaces the download.
- data-slot="data-table-filter-chip"
One chip per active filter: the column, how it matches (is, is any of, contains, between) and the value. The label opens the editor, the cross removes it, and Reset filters clears all.
- data-slot="data-table-sort"
A column header with the sort button, a direction icon and, once two columns are sorted, a number for the order. Every sortable header reports its sort order.
- data-slot="data-table-column-menu"
A small button beside each heading with sort ascending or descending, Then by, Clear sort, Pin to start or end, and Hide column.
One row of cells. It turns page tone on hover and subtle tone while selected, and the first data column is primary text with the rest secondary.
- data-slot="data-table-details"
The panel under an opened row, drawn by a sub row renderer. A chevron column is added when you pass one.
- data-slot="data-table-action-bar"
A floating bar named Selection actions with the count, your bulk actions, Select all, Export selected and Clear. It sticks to the bottom of the screen while the table runs past it.
How many rows are selected out of the total, or just the row count when selecting is off.
Rows per page and the page buttons. Turning paging off removes both and shows every row.
Replaces the rows: skeleton rows while loading, an empty state, a No results state with Reset filters, and an error with Try again when you pass a retry handler. Toolbar and header stay.
Best practices
- Do
Name the grid with an aria-label and each row with a row label, so a checkbox reads Select INV-2001 instead of Select row 3.
- Do
Pass a stable row id. Selection is kept by id, so without it a selection follows the position of a row when you sort or page.
- Do
Keep columns and data stable: module constants, state or useMemo. A new array on every render makes the table recompute its rows.
- Do
Pass loading, an error with a retry handler and, where it helps, an empty state. The table draws the skeleton rows, the alert and the empty message itself and keeps the toolbar.
- Do
With server-side data, list the choices of a select filter yourself. The loaded rows are only one page, so reading the choices from them would hide most of them.
- Do
Keep the query in the address bar with the URL state hook, under its own prefix, so a reload or a shared link opens the same view.
- Don’t
Don't sort, filter or page the rows yourself before passing them in. Let the table do it, or use server-side mode and answer the query callback with the matching page.
- Don’t
Don't put thousands of rows on one page with paging off. Every row is rendered, because the table does not virtualise.
- Don’t
Don't rely on the table for inline editing or column resizing. Neither exists; a cell can hold a control, but the table does not manage it.
API reference
DataTable is a plain component, so this table lists every prop. Column definitions are TanStack column definitions with extra meta keys.
The whole table in one bordered box: a toolbar, filter chips, the grid, an action bar while rows are selected, and a footer. Its state reads ready, loading, empty or error.
Notes for AI
Give your coding assistant the Markdown reference instead of screenshots.
get_component("data-table")The full library index for assistants is at /llms.txt.