The slotsmith data table is a React table built on TanStack Table, with sorting, selection, pagination, tree rows, virtual rows and row reorder built in. Every part it renders is a slot: keep the fallbacks, or pass your design system’s own components.

Overview

The demo below uses the fallbacks only. Click a header to sort, shift-click a second header to sort by both, tick rows to select them, and change the page size under the table.

Status
Lena ParkEngineerPlatformActive
Omar HaddadDesignerProductActive
Sofia ReyesEngineerPaymentsAway
Yuki TanakaManagerPlatformActive
Amir NasserAnalystGrowthActive

No rows selected.

Each feature has a guide with its own live demo: sorting and selection, pagination, server data with loading, empty and error states, tree rows, virtual rows for long lists, row reorder by pointer, touch or keyboard, footers, and the headless hook for your own markup.

Install

npm i slotsmith @tanstack/react-table

VirtualDataTable from slotsmith/virtual also needs @tanstack/react-virtual.

import "slotsmith/data-table.css";

Import the stylesheet once, at your app's entry. slotsmith/styles.css holds every component's styles instead.

Quick start

Pass data and columns. Columns are TanStack Table column definitions; getRowId gives each row a stable id.

Things Fall ApartChinua Achebe1958
Season of Migration to the NorthTayeb Salih1966
The Left Hand of DarknessUrsula K. Le Guin1969
BelovedToni Morrison1987
The Remains of the DayKazuo Ishiguro1989
Wolf HallHilary Mantel2009

Guides

  • Sorting and selectionSort the slotsmith data table by one or more columns, and select rows with checkboxes, controlled or uncontrolled, with a rule for rows that cannot be selected.
  • PaginationSplit the slotsmith data table into pages, control the page and page size, change the page-size options, or hide the controls.
  • Server dataPage and sort the slotsmith data table on a server with manualPagination, manualSorting and rowCount, and show loading, error and empty states.
  • Tree rowsShow nested rows in the slotsmith data table with getSubRows, and control which rows are expanded.
  • Virtual rowsRender long lists in the slotsmith data table with the virtual prop, which draws only the rows in view.
  • Row reorderLet people drag rows of the slotsmith data table into a new order by pointer, touch or keyboard, in flat and tree tables, and store the order.
  • Spreadsheet modeEdit the slotsmith data table like a spreadsheet: select cells, type over them, paste from Excel, drag the fill handle and undo.
  • FootersAdd a footer row to the slotsmith data table, such as a total, from each column's footer definition.
  • The headless hookRender the slotsmith data table in markup of your own with useDataTable: the state, the TanStack Table instance and row reorder, with no UI.

Reference

The API page is generated from the library’s source, so it lists every slot, prop and label the installed version has.

Adapters

The table works with any design system. Each slot takes a component, so a library’s own table, checkbox, button and select can replace the fallbacks. The Adapters page has ready slot maps for shadcn/ui, MUI, Chakra, Ant Design and Radix Themes, as examples of well-known libraries; the same approach works with your own.

Accessibility

The table renders a real <table>, so screen readers announce rows, columns and headers. What the fallbacks add:

  • Sorting. A sortable header holds a <button>, and its <th> carries aria-sort (ascending, descending or none). With enableMultiSort, shift-click adds a column to the sort. See sorting and selection.
  • Selection. Each row and the header have a checkbox named by the selectRow and selectAll labels; the header checkbox is indeterminate while some rows on the page are selected. See sorting and selection.
  • Tree rows. The expand toggle is a <button> with aria-expanded, named by expandRow or collapseRow. See tree rows.
  • Pagination. The controls sit in a <nav> named by the pagination label. The previous and next buttons are named by previousPage and nextPage, and the page counter is an aria-live="polite" region, so a page change is read out. The page-size control is the slotsmith Autocomplete, a combobox named by the visible rowsPerPage text. See pagination.
  • Loading and errors. While loading, the root has aria-busy="true" and the skeleton rows are hidden from assistive technology. The error state has role="alert" and a retry button. See server data.
  • Row reorder. Each drag handle is a <button> named by reorderRow, with aria-describedby pointing at hidden instructions (reorderInstructions) and aria-pressed="true" while it is lifted from the keyboard. A visually hidden live region (role="status", aria-live="assertive") reads each step with the reorderLifted, reorderMoved, reorderDropped and reorderCancelled labels, as positions such as “Position 2 of 5”. In a tree table, a row with no visible sibling has its handle disabled. See row reorder.

Moving a row from the keyboard, with focus on its drag handle:

KeysAction
SpaceEnterLift the row.
↑↓Move the lifted row up or down one place among its siblings.
SpaceEnterDrop the row in its new place. Focus stays on its handle.
EscCancel. The row goes back where it was.
TabCancel, and move focus on as usual. Leaving the handle any other way cancels too.

Every label can be translated or replaced; see Labels & locales.

Limitations

FAQ

Does the data table support server-side pagination?

Yes. Set manualPagination, pass the current page as data and the total as rowCount, and fetch the next page in onPaginationChange. Server-side sorting works the same way with manualSorting.

See it in the docs

Can I use virtual rows and row reorder together?

Yes. Pass virtual with useVirtualizer as use and set enableRowReorder: the dragged row stays rendered while it scrolls out of the window, the view scrolls under it near the edges, and the keyboard scrolls to the row it moves to.

See it in the docs

Can I render custom cells?

Yes. Columns are TanStack Table column definitions, so a column's cell function can return any React node. To change the cell element itself, replace the Cell slot.

See it in the docs

Which TanStack Table version does it need?

TanStack Table 9: install @tanstack/react-table ^9.2.0 next to slotsmith. Virtual rows also need @tanstack/react-virtual ^3.10.0, whose useVirtualizer you pass in as virtual.use.

See it in the docs