Data table
Data table is one table for every list people work through. Selection is always the first column, every action lives in one toolbar above the rows, and the same parts hold up from a wide dashboard down to a phone. TanStack Table works out the rows and keeps the state; Data table draws them in a native table.
| Last active | Actions | ||||||
|---|---|---|---|---|---|---|---|
| Select | MOMaya Okafor | Design | Admin | Active | 12 | Today | |
| Select | PRPriya Raman | Engineering | Editor | Away | 8 | Yesterday | |
| Select | JAJordan Alvarez | Marketing | Editor | Active | 5 | Today | |
| Select | SWSam Whitfield | Support | Viewer | Invited | 0 | Never | |
| SelectThe workspace owner can't be removed | EMElena Marsh | Operations | Owner | Active | 21 | Today |
Examples
Search, filters and pages
The table sorts, searches, filters and pages its own rows from its state.
| Last active | Actions | ||||||
|---|---|---|---|---|---|---|---|
| Select | MOMaya Okafor | Design | Admin | Active | 12 | Today | |
| Select | PRPriya Raman | Engineering | Editor | Away | 8 | Yesterday | |
| Select | JAJordan Alvarez | Marketing | Editor | Active | 5 | Today | |
| Select | SWSam Whitfield | Support | Viewer | Invited | 0 | Never | |
| SelectThe workspace owner can't be removed | EMElena Marsh | Operations | Owner | Active | 21 | Today | |
| Select | RDRosa Delgado | Engineering | Viewer | Deactivated | 3 | Aug 14 |
| Last active | Actions | ||||||
|---|---|---|---|---|---|---|---|
| Select | MOMaya Okafor | Design | Admin | Active | 12 | Today | |
| Select | PRPriya Raman | Engineering | Editor | Away | 8 | Yesterday | |
| Select | JAJordan Alvarez | Marketing | Editor | Active | 5 | Today | |
| Select | SWSam Whitfield | Support | Viewer | Invited | 0 | Never |
Loading
Set loading while the data is on its way. The body shows skeleton rows
shaped like the visible columns, narrow cards show skeleton cards, and the
table is aria-busy. Both keep the real rows' height, so nothing jumps when
the data arrives. A hand-written body can render DataTableSkeleton itself.
| Last active | Actions |
|---|
| Last active | Actions |
|---|
Empty and no matches
With no rows, the table says so in place of the body. When a search or filter
hid them, it says nothing matched and offers Clear filters, which puts focus
back in the search. Pass empty for your own copy, such as an EmptyState with
an invite button, or empty={null} for a blank body.
| Last active | Actions | ||||||
|---|---|---|---|---|---|---|---|
No members yet | |||||||
| Last active | Actions | ||||||
|---|---|---|---|---|---|---|---|
| Select | MOMaya Okafor | Design | Admin | Active | 12 | Today | |
| Select | PRPriya Raman | Engineering | Editor | Away | 8 | Yesterday | |
| Select | JAJordan Alvarez | Marketing | Editor | Active | 5 | Today | |
| Select | SWSam Whitfield | Support | Viewer | Invited | 0 | Never | |
| SelectThe workspace owner can't be removed | EMElena Marsh | Operations | Owner | Active | 21 | Today | |
| Select | RDRosa Delgado | Engineering | Viewer | Deactivated | 3 | Aug 14 |
In the URL
Sorting, the search, filters and the page can each live in a search param,
so a link opens the same view. useSearchParamsAtom writes with
history.replaceState, so typing a search doesn't fill the back button. It
starts empty on the server and in the first render, so hydration matches,
and applies the URL's value once mounted.
| Last active | Actions | ||||||
|---|---|---|---|---|---|---|---|
| Select | MOMaya Okafor | Design | Admin | Active | 12 | Today | |
| Select | PRPriya Raman | Engineering | Editor | Away | 8 | Yesterday | |
| Select | JAJordan Alvarez | Marketing | Editor | Active | 5 | Today | |
| Select | SWSam Whitfield | Support | Viewer | Invited | 0 | Never |
Rows
| Last active | Actions | ||||||
|---|---|---|---|---|---|---|---|
| Select | SWSam Whitfield | Support | Viewer | Invited | 0 | Never | |
| SelectThe workspace owner can't be removed | EMElena Marsh | Operations | Owner | Active | 21 | Today | |
| Select | RDRosa Delgado | Engineering | Viewer | Deactivated | 3 | Aug 14 |
| Last active | Actions | ||||||
|---|---|---|---|---|---|---|---|
| Select | MOMaya Okaformaya@example.com | Design | Admin | Active | 12 | Today | |
| Select | PRPriya Ramanpriya@example.com | Engineering | Editor | Away | 8 | Yesterday | |
| Select | JAJordan Alvarezjordan@example.com | Marketing | Editor | Active | 5 | Today | |
| Select | SWSam Whitfieldsam@example.com | Support | Viewer | Invited | 0 | Never | |
| SelectThe workspace owner can't be removed | EMElena Marshelena@example.com | Operations | Owner | Active | 21 | Today | |
| Select | RDRosa Delgadorosa@example.com | Engineering | Viewer | Deactivated | 3 | Aug 14 |
Bulk actions
Every table's bulk actions read in one order: your actions, then More, then Delete behind a divider. An action that works on one row stays in place, dimmed, while more are selected. They act on every selected row, including any a search or filter hides, and the toolbar says how many those are.
Delete only
| Last active | Actions | ||||||
|---|---|---|---|---|---|---|---|
| Select | MOMaya Okafor | Design | Admin | Active | 12 | Today | |
| Select | PRPriya Raman | Engineering | Editor | Away | 8 | Yesterday |
Export
| Last active | Actions | ||||||
|---|---|---|---|---|---|---|---|
| Select | MOMaya Okafor | Design | Admin | Active | 12 | Today | |
| Select | PRPriya Raman | Engineering | Editor | Away | 8 | Yesterday |
Several
| Last active | Actions | ||||||
|---|---|---|---|---|---|---|---|
| Select | MOMaya Okafor | Design | Admin | Active | 12 | Today | |
| Select | PRPriya Raman | Engineering | Editor | Away | 8 | Yesterday |
One item, with two selected
| Last active | Actions | ||||||
|---|---|---|---|---|---|---|---|
| Select | MOMaya Okafor | Design | Admin | Active | 12 | Today | |
| Select | PRPriya Raman | Engineering | Editor | Away | 8 | Yesterday |
| Last active | Actions | ||||||
|---|---|---|---|---|---|---|---|
| Select | MOMaya Okaformaya@example.com | Design | Admin | Active | 12 | Today | |
| Select | PRPriya Ramanpriya@example.com | Engineering | Editor | Away | 8 | Yesterday | |
| Select | JAJordan Alvarezjordan@example.com | Marketing | Editor | Active | 5 | Today | |
| Select | SWSam Whitfieldsam@example.com | Support | Viewer | Invited | 0 | Never | |
| SelectThe workspace owner can't be removed | EMElena Marshelena@example.com | Operations | Owner | Active | 21 | Today | |
| Select | RDRosa Delgadorosa@example.com | Engineering | Viewer | Deactivated | 3 | Aug 14 |
Across pages
Select the page, and the toolbar offers every matching row. Show selected only hands the filtering to the app, which keeps the selection in an atom it reads.
| Last active | Actions | ||||||
|---|---|---|---|---|---|---|---|
| Select | MOMaya Okafor | Design | Admin | Active | 12 | Today | |
| Select | PRPriya Raman | Engineering | Editor | Away | 8 | Yesterday | |
| Select | JAJordan Alvarez | Marketing | Editor | Active | 5 | Today | |
| Select | SWSam Whitfield | Support | Viewer | Invited | 0 | Never | |
| SelectThe workspace owner can't be removed | EMElena Marsh | Operations | Owner | Active | 21 | Today |
On a phone
Under 32rem of its own width, the table scrolls under an icon-only toolbar, or each row becomes a card read from the same rows, so the search, sort and pages work the same. Filters move into a sheet.
| Last active | Actions | ||||||
|---|---|---|---|---|---|---|---|
| Select | MOMaya Okafor | Design | Admin | Active | 12 | Today | |
| Select | PRPriya Raman | Engineering | Editor | Away | 8 | Yesterday | |
| Select | JAJordan Alvarez | Marketing | Editor | Active | 5 | Today | |
| Select | SWSam Whitfield | Support | Viewer | Invited | 0 | Never | |
| SelectThe workspace owner can't be removed | EMElena Marsh | Operations | Owner | Active | 21 | Today | |
| Select | RDRosa Delgado | Engineering | Viewer | Deactivated | 3 | Aug 14 |
| Last active | Actions | ||||||
|---|---|---|---|---|---|---|---|
| Select | MOMaya Okafor | Design | Admin | Active | 12 | Today | |
| Select | PRPriya Raman | Engineering | Editor | Away | 8 | Yesterday | |
| Select | JAJordan Alvarez | Marketing | Editor | Active | 5 | Today | |
| Select | SWSam Whitfield | Support | Viewer | Invited | 0 | Never | |
| SelectThe workspace owner can't be removed | EMElena Marsh | Operations | Owner | Active | 21 | Today | |
| Select | RDRosa Delgado | Engineering | Viewer | Deactivated | 3 | Aug 14 |
In a form
As a picker, the selection is the form's value and the footer counts it.
| Select | Onboarding checklist | Workspace |
| Select | Brand guidelines | Public |
| Select | Release notes | Public |
Reading and owning state
The component that calls useDataTable doesn't re-render when the state
changes; each part subscribes to what it shows, so ticking a row re-renders
that row and the toolbar, not the table. To read state there, pass a
selector, useDataTable(options, (state) => state.rowSelection), and read
table.state, or use table.Subscribe. Act on the selection with
table.getSelectedRowIds() and table.resetRowSelection(). The selection
holds every selected row still in the data: ids a refetch drops leave it,
but rows a search or filter hides stay selected, and the toolbar, the
announcement and DataTableSelectionCount say how many, as in “5 members
selected, 2 hidden by filters”. Bulk actions act on all of them, hidden
ones included, and Delete's description gives the count. The header
checkbox speaks for the page; Select all matching adds every row the
filters let through and keeps the hidden ones; Clear and Escape clear
everything. With manualPagination, ids on other pages stay, since the app
owns those.
What it registers
dataTableFeatures registers only what Data table uses, so a table carries
nothing else: sorting (text, alphanumeric, basic and datetime
comparators), column and global filtering (includesString, equals and
arrHas), faceted unique values, pagination, row selection, column
visibility and column pinning. Grouping, expanding, resizing, ordering and
row pinning are left out.
Migrating to the table API
The rowIds, totalCount, value, defaultValue and onValueChange
props, useDataTableSelection, and hand-written DataTableRow,
DataTableCell and DataTableHead are deprecated in fibo 0.2.0 and removed
in 0.3.0. Until then they run on the same TanStack table as the new API,
built from rowIds with selection only, so they behave as they did. A
codemod lists every use with its file and line; it changes nothing, since
writing column definitions needs a person.
pnpm dlx jscodeshift --parser tsx --dry \
-t https://fibo.toribryan.com/codemods/data-table-legacy-api.js src- 01
rowIdsbecomesdata, your rows themselves, each with anid. - 02Each
DataTableHeadand the cells under it become one column: itsheader, acellrenderer for what the cell held, andmeta.type.secondary,iconandavatarmove tometa. - 03
pinnedbecomes the table'scolumnPinningstate, by column id. - 04
lockedReasonmoves from each row to one function onuseDataTable. - 05
valueandonValueChangebecomestate.rowSelectionandonRowSelectionChange, a record of ids rather than a Set."all"is gone: Select all matching selects every matching id the table has loaded. - 06
totalCountbecomesrowCountwithmanualPagination, when the app pages on a server. - 07Sorting, filtering and paging that the app did itself can go: the table does them from its state.
Anatomy
A native table inside a box that measures its own width. The toolbar sits
above it, and the cards replace it on a narrow screen. Both draw the rows
from the same TanStack row model. The narrow Filters button opens a
sheet, data-table-filters-sheet, holding the sort and filter controls.
| Actions | ||||||
|---|---|---|---|---|---|---|
| Select | MOMaya Okafor | Design | Admin | Active | 12 | |
| Select | PRPriya Raman | Engineering | Editor | Away | 8 | |
| Select | JAJordan Alvarez | Marketing | Editor | Active | 5 | |
| Select | SWSam Whitfield | Support | Viewer | Invited | 0 | |
| SelectThe workspace owner can't be removed | EMElena Marsh | Operations | Owner | Active | 21 | |
| Select | RDRosa Delgado | Engineering | Viewer | Deactivated | 3 |
Guidelines
- 01Selection is always the first column, and row actions are always the last, pinned to the end.
- 02Let the table sort, filter and page: give useDataTable all the rows, or set the manual options and load the rows its state describes. Don't sort or filter the rows yourself as well.
- 03Keep sorting, the search, filters and the page in the URL with useSearchParamsAtom when people share or bookmark the list.
- 04Give a column that people filter by a few values filterFn: "arrHas" and a DataTableFacetFilter, so the menu shows how many rows hold each.
- 05Pin the row's name to the start and at most one must-see column, usually status, to the end.
- 06Rows are 40 pixels, or 52 with secondary text. Nothing goes taller.
- 07Lock a row that can't be selected, and say why in useDataTable's lockedReason.
- 08Pin one column to each edge at most. Pinned columns stick at a fixed offset, so a second one would sit over the first.
- 09In a picker, put DataTableSelectionCount in the footer, so people see how many they've chosen.
- 10Put every action in the toolbar. Don't add hover actions or a floating bar; they split actions across places.
- 11Keep the bulk action order: your actions, then More, then Delete. Approve comes before Deny.
- 12Give a bulk action that works on one row
single, so it stays in place, dimmed, while more are selected. - 13Give actions an icon, so they still fit on a phone. Under 32rem they show the icon alone, with the label as their name and tooltip.
- 14Use
narrowLayout="cards"when a row reads better as a summary than as a line, such as people with a status. Keep scroll for data people compare across columns.
Best practices
Accessibility
- 01It's a native table, not a grid: checkboxes and buttons are ordinary Tab stops. TanStack Table only works out the rows; the markup is Data table's.
- 02Every head carries scope="col". A sortable head holds a button named by the column. Only the sorted head carries aria-sort, ascending or descending, so the order is announced once, where it applies.
- 03DataTableSearch is a search field; give it an aria-label when there's no visible label. Facet filter menus name each choice with its count, “Active 3”, and say how many are ticked on the button.
- 04Name it with aria-label or aria-labelledby on DataTable.
- 05Each row checkbox is named from its primary or person cell, “Select Maya Okafor”, or from the row's label when it has neither. Select all says its scope, “Select all members on this page”.
- 06A locked row's checkbox is disabled and described by the reason. The lock is focusable, so keyboard users can open its tooltip.
- 07Selection changes are announced through a status region once they take effect, so a change a controlled parent turns down isn't announced. Selected rows a filter hides are counted: “5 members selected, 2 hidden by filters”. Escape clears the selection.
- 08The toolbar is a group named “Filters and actions” or “Bulk actions”, not a toolbar role, so its controls stay ordinary Tab stops and arrow keys stay with the search field.
- 09When the focused control goes away, such as Clear or Select all matching, focus moves to Clear, or to select all when nothing is selected, instead of the page.
- 10A single-row action that's dimmed stays focusable and is described by why: “Works on one member at a time”.
- 11Only one of the table and the cards is ever in the page, so screen readers don't meet each row twice. Cards are a list, and each card's checkbox is named from its title.
- 12Icon-only actions on a narrow table keep their label as their accessible name and show it as a tooltip.
- 13Status badges sit on the background, so their tints keep AA contrast on selected and hovered rows.
Related components
- Filter menuA filter menu of fields and values that turns into a search as you type.
- Command menuA Cmd+K palette with nested pages, recent commands, ranked search and a preview pane.