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 activeActions
MOMaya Okafor
Design
Admin
Active
12
Today
PRPriya Raman
Engineering
Editor
Away
8
Yesterday
JAJordan Alvarez
Marketing
Editor
Active
5
Today
SWSam Whitfield
Support
Viewer
Invited
0
Never
EMElena Marsh
Operations
Owner
Active
21
Today
Data tableSort by a header, search, filter by status or team, or hide a column. Select a row and the toolbar swaps in place to the count and bulk actions. Shift-click selects a range, and Escape clears.

Examples

Search, filters and pages

The table sorts, searches, filters and pages its own rows from its state.

Last activeActions
MOMaya Okafor
Design
Admin
Active
12
Today
PRPriya Raman
Engineering
Editor
Away
8
Yesterday
JAJordan Alvarez
Marketing
Editor
Active
5
Today
SWSam Whitfield
Support
Viewer
Invited
0
Never
EMElena Marsh
Operations
Owner
Active
21
Today
RDRosa Delgado
Engineering
Viewer
Deactivated
3
Aug 14
Faceted filtersOne Filter menu covers every filterable column. Each value shows how many rows hold it under the other filters, so a choice never leads to an empty table.
Last activeActions
MOMaya Okafor
Design
Admin
Active
12
Today
PRPriya Raman
Engineering
Editor
Away
8
Yesterday
JAJordan Alvarez
Marketing
Editor
Active
5
Today
SWSam Whitfield
Support
Viewer
Invited
0
Never
With paginationFour rows to a page. Sorting, the search and filters start it again from the first page; new data keeps the page.

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 activeActions
Last activeActions
LoadingPress Finish loading. The rows land where the skeletons were.

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 activeActions

No members yet

Last activeActions
MOMaya Okafor
Design
Admin
Active
12
Today
PRPriya Raman
Engineering
Editor
Away
8
Yesterday
JAJordan Alvarez
Marketing
Editor
Active
5
Today
SWSam Whitfield
Support
Viewer
Invited
0
Never
EMElena Marsh
Operations
Owner
Active
21
Today
RDRosa Delgado
Engineering
Viewer
Deactivated
3
Aug 14
Empty and no matchesSearch the second table for something that isn't there.

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 activeActions
MOMaya Okafor
Design
Admin
Active
12
Today
PRPriya Raman
Engineering
Editor
Away
8
Yesterday
JAJordan Alvarez
Marketing
Editor
Active
5
Today
SWSam Whitfield
Support
Viewer
Invited
0
Never
No search params yet
URL-synced stateSort, page or search and watch the params below the table, and the address bar, change. Reload and the view comes back.

Rows

Last activeActions
SWSam Whitfield
Support
Viewer
Invited
0
Never
EMElena Marsh
Operations
Owner
Active
21
Today
RDRosa Delgado
Engineering
Viewer
Deactivated
3
Aug 14
Locked rowThe workspace owner can't be selected. The lock says why on hover or focus, and select all leaves her out.
Last activeActions
MOMaya Okaformaya@example.com
Design
Admin
Active
12
Today
PRPriya Ramanpriya@example.com
Engineering
Editor
Away
8
Yesterday
JAJordan Alvarezjordan@example.com
Marketing
Editor
Active
5
Today
SWSam Whitfieldsam@example.com
Support
Viewer
Invited
0
Never
EMElena Marshelena@example.com
Operations
Owner
Active
21
Today
RDRosa Delgadorosa@example.com
Engineering
Viewer
Deactivated
3
Aug 14
Secondary textA second line under each name. Rows grow from 40 to 52 pixels, and nothing goes taller.

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

2 members selected
Last activeActions
MOMaya Okafor
Design
Admin
Active
12
Today
PRPriya Raman
Engineering
Editor
Away
8
Yesterday

Export

2 members selected
Last activeActions
MOMaya Okafor
Design
Admin
Active
12
Today
PRPriya Raman
Engineering
Editor
Away
8
Yesterday

Several

2 members selected
Last activeActions
MOMaya Okafor
Design
Admin
Active
12
Today
PRPriya Raman
Engineering
Editor
Away
8
Yesterday

One item, with two selected

2 members selected
Last activeActions
MOMaya Okafor
Design
Admin
Active
12
Today
PRPriya Raman
Engineering
Editor
Away
8
Yesterday
Bulk action patterns
2 members selected
Last activeActions
MOMaya Okaformaya@example.com
Design
Admin
Active
12
Today
PRPriya Ramanpriya@example.com
Engineering
Editor
Away
8
Yesterday
JAJordan Alvarezjordan@example.com
Marketing
Editor
Active
5
Today
SWSam Whitfieldsam@example.com
Support
Viewer
Invited
0
Never
EMElena Marshelena@example.com
Operations
Owner
Active
21
Today
RDRosa Delgadorosa@example.com
Engineering
Viewer
Deactivated
3
Aug 14
Review queueApprove then Deny, and no Delete. Second lines carry the details.

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 activeActions
MOMaya Okafor
Design
Admin
Active
12
Today
PRPriya Raman
Engineering
Editor
Away
8
Yesterday
JAJordan Alvarez
Marketing
Editor
Active
5
Today
SWSam Whitfield
Support
Viewer
Invited
0
Never
EMElena Marsh
Operations
Owner
Active
21
Today
A directory, five to a page

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 activeActions
MOMaya Okafor
Design
Admin
Active
12
Today
PRPriya Raman
Engineering
Editor
Away
8
Yesterday
JAJordan Alvarez
Marketing
Editor
Active
5
Today
SWSam Whitfield
Support
Viewer
Invited
0
Never
EMElena Marsh
Operations
Owner
Active
21
Today
RDRosa Delgado
Engineering
Viewer
Deactivated
3
Aug 14
Scroll
1 member selected
Last activeActions
MOMaya Okafor
Design
Admin
Active
12
Today
PRPriya Raman
Engineering
Editor
Away
8
Yesterday
JAJordan Alvarez
Marketing
Editor
Active
5
Today
SWSam Whitfield
Support
Viewer
Invited
0
Never
EMElena Marsh
Operations
Owner
Active
21
Today
RDRosa Delgado
Engineering
Viewer
Deactivated
3
Aug 14
Cards

In a form

As a picker, the selection is the form's value and the footer counts it.

Onboarding checklist
Workspace
Brand guidelines
Public
Release notes
Public
2 of 3 documents selected
Picker

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
  • 01rowIds becomes data, your rows themselves, each with an id.
  • 02Each DataTableHead and the cells under it become one column: its header, a cell renderer for what the cell held, and meta.type. secondary, icon and avatar move to meta.
  • 03pinned becomes the table's columnPinning state, by column id.
  • 04lockedReason moves from each row to one function on useDataTable.
  • 05value and onValueChange become state.rowSelection and onRowSelectionChange, a record of ids rather than a Set. "all" is gone: Select all matching selects every matching id the table has loaded.
  • 06totalCount becomes rowCount with manualPagination, 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
MOMaya Okafor
Design
Admin
Active
12
PRPriya Raman
Engineering
Editor
Away
8
JAJordan Alvarez
Marketing
Editor
Active
5
SWSam Whitfield
Support
Viewer
Invited
0
EMElena Marsh
Operations
Owner
Active
21
RDRosa Delgado
Engineering
Viewer
Deactivated
3
Column visibility and pinningColumns shows and hides every column that can hide; Last active starts hidden. Scroll it sideways: the name and the actions stay put, with a shadow where there's more under them.

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

Elena MarshLocked
DoShow why a row can't be selected.
Elena Marsh
Don'tDon't disable a row without a reason. People can't tell it's on purpose.

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.

References