GitHub

Data Table

A table driven by column configuration, with local or remote data, search, filters, selection and plugins.

Loading example…

Installation

pnpm dlx shadcn@latest add @sui/data-table

Install with the shadcn CLI or use the shared @workspace/ui package. Follow the installation guide to configure the registry, load styles, and choose import aliases.

DataTable installs as components/ui/data-table/index.tsx. If you installed it from SUI 5.4 or earlier, delete the old components/ui/data-table.tsx after updating: a file beside the folder wins over its index, so imports would keep the old version. See Update installed source.

import { DataTable, type DataTableColumn } from "@workspace/ui/components/data-table"

Usage

Describe each column once with plain fields. valueType formats cells, valueEnum renders badges and adds a quick filter, search adds a query form field, and sortable adds a header menu.

const columns: DataTableColumn<User>[] = [
  { key: "name", title: "Name", keyword: true, sortable: true },
  { key: "status", title: "Status", valueEnum: statusOptions },
  { key: "amount", title: "Spend", valueType: "money", align: "end", sortable: true },
  { key: "createdAt", title: "Created", valueType: "date", search: true },
  { key: "profile.city", title: "City", hidden: true },
  { id: "actions", title: "Actions", fixed: "end", render: (user) => <RowMenu user={user} /> },
]

<DataTable rowKey="id" columns={columns} data={users} />

key accepts typed dot paths, and render(value, row) receives the value type of that path. A column with id and no key is a display column such as row actions.

Pass data to sort, filter and page in the browser, or request to let the server do it:

<DataTable
  rowKey="id"
  columns={columns}
  request={async ({ page, pageSize, sort, keyword, search, filters, advanced, signal }) => {
    const response = await fetch(`/api/users?${toQuery({ page, pageSize, sort, keyword, search, filters })}`, { signal })
    return response.json() // { data, total }
  }}
/>

Requests are cancelled when parameters change, so late responses never replace newer rows. Without total, pagination shows previous and next only.

Local data and toolbar plugins

Columns with keyword share the toolbar search box. Enum columns get quick filters with option counts. Features beyond the core are plugins: density(), columnSettings() (visibility, drag ordering, pinning and header-edge width handles) and exportCsv() (current page, every match, or the selection).

The toolbar stays on one row. The search box and filters scroll sideways and the actions stay at the end. Date range columns sit on the row next to the quick filters, with search.presets for quick ranges such as the last seven days. Past maxFilters (2 by default), the first filter stays and the rest share one Filters button (DataTableMoreFilters), applied together. The filters are a light Data Form: each quick filter is a compact button that sums up its value and applies at once, and the Filters panel is a draft form applied with Apply. Add lightForm({ maxFilters }) to set it among other plugins. A column chooses where its quick filter goes with filter: "inline" (its dropdown on the row), "popover" (the default, with option counts) or "more" (always in Filters); date ranges take search: { lightMode }. On phones only the search box stays on the row. The toolbarSearch slot adds inputs right after the search box, and DataTableChoiceMenu is an icon button with a single-choice menu for toolbar options.

Loading example…
Loading example…

Value types

valueTypeCellDefault search field
textPlain text; ellipsis and copyable add LongText and CopyTexttext
number, money, percentIntl.NumberFormat; set format, such as { currency: "CNY" }numberRange
date, datetimeIntl.DateTimeFormat with the locale of the labelsdateRange, datetimeRange
enumBadge from valueEnum, with color per optionselect
booleanYes or No from labelsboolean
Loading example…

Query form

queryForm() builds a collapsible multi-field form from columns with search. Fields apply together when submitted. Field types are text, number, numberRange, select, multiSelect, date, dateRange, datetimeRange, boolean and custom (with render). Use order and colSpan for placement, options as a function and dependencies for linked fields such as province and city, searchOnly for fields without a table column, and transform to rename request parameters, for example a date range to { createdFrom, createdTo }.

The form is a Data Form grid, so search also takes field options such as reactions, validators, valueType and fieldProps. Values keep the shapes the table stores, such as local date strings, so URL sync and requests read them as before.

Loading example…

Advanced filter

advancedFilter() adds a builder for field, operator and value rules joined with AND or OR. Operators follow the value type of each column. Pass storageKey to save named views in local storage.

Loading example…

Editing rows

editable({ onSave }) edits a row in place. Each data column becomes the control of its value type, with the same validation and linking as a Data Form field; form on a column adds field options such as required, or form: false keeps it as text. Enter in a text field saves and Escape cancels; keys inside a select or calendar stay with that control. The Edit, Save and Cancel buttons sit in a column pinned to the end, kept out of column settings and exports. Return or throw { fields, form } from onSave to show errors in the row; the row stays open until a save succeeds, and the page updates its own rows.

Loading example…

access maps column keys to hidden, which leaves a column out of the table, its filters and its exports, or readonly, which keeps editable() from editing it. An inline map can be written in place; a function is compared by identity, so memoize it.

Forms from columns

toFormFields(columns) turns the table's columns into DataForm fields, so one definition serves the table, its filters, its row editing and its create and edit forms. The table's value types are DataForm value types too (a boolean column edits as a switch), valueEnum becomes the options, and form on a column adds field options or leaves it out.

Loading example…

Clearing conditions

The toolbar stays one row. Each control already shows and clears its own value: the search box, the quick-filter badges, the date fields and the query form's fields. While any condition applies (a keyword, a search field, a quick filter or advanced rules), a Clear all button follows the filter controls on the same row and resets them together; with no conditions it is hidden. The query form keeps its own Reset.

Pass chips to also list the active conditions as removable chips below the toolbar, with their own clear-all button, for tables whose conditions are not all visible in the toolbar.

Loading example…

Selection, bulk actions and expandable rows

rowSelection adds a checkbox column; selections persist across pages. bulkActions([{ label, icon, onClick, variant }]) shows a floating bar of icon buttons, with labels as tooltips, above the pagination while rows are selected; pass a render function instead for custom content. Escape clears the selection. expandable(render) adds a toggle that reveals details with height motion.

Loading example…

Drag sorting

dragSort({ onDragEnd }) adds a handle column. Rows move by pointer or keyboard (Space, arrow keys, Space). Sorting and pagination are off while it is active.

Loading example…

Large lists

virtual() renders only the rows in view. Use it with pagination={false}; it turns off row layout animation.

Loading example…

Layout

The default layout="fill" takes the height of its parent like an admin page: the query form and toolbar stay at the top, rows scroll with a sticky header, and pagination stays at the bottom. Give the parent a height, for example AppMain with flex-1 min-h-0, or a fixed h-[640px] container. The table itself is only as tall as its rows: with a few rows the space falls between the table and the pagination, and with many it stops at the space left and scrolls. Use layout="auto" inside cards and dialogs to grow with the rows.

Loading example…

On narrow screens rows become cards. Mark the heading column with primary, or set responsive={false} to keep the table.

Composition

useDataTable returns the same table the component uses. Pass it to DataTable with children to arrange the parts yourself: DataTableToolbar, DataTableSearch, DataTableFacetedFilter, DataTableFilterChips, DataTableSlotContent, DataTableContent and DataTablePagination. The table also exposes state such as total, selection and state, and actions such as reload().

Loading example…

Views

views({ grid, list, defaultView, onOpen }) lets readers switch the rows between the table, a list built from the columns, and a grid of cards when grid renders a row as a card. persist remembers the view a reader picked. Plugins can render views of their own with renderView, and the table exposes view and setView().

Loading example…

URL sync and persistence

urlSync({ prefix }) keeps pagination, sorting, keyword, query form values, quick filters and advanced rules in the address bar with history.replaceState, without a router dependency. persist({ key }) remembers column visibility, order, pinning, widths and density. proPlugins() combines the query form, advanced filter, reload, density, column settings, CSV export and URL sync.

<DataTable
  rowKey="id"
  columns={columns}
  request={fetchUsers}
  rowSelection
  plugins={[...proPlugins<User>(), persist({ key: "users-table" }), bulkActions([{ label: "Delete", icon: <Trash2 />, variant: "destructive", onClick: deleteUsers }])]}
/>

Memoize the plugin list, for example with useMemo, so columns and features are not rebuilt on every render.

Plugins

A plugin is an object with a name and any of these hooks into the core:

FieldPurpose
slotsRender into header, toolbarStart, toolbarSearch, toolbarFilters (replaces the filters on the row), toolbarEnd or floating
columnsAdd utility columns, such as checkboxes or handles
featuresTurn on virtual, dragSort, expandable or resizable
defaultView, initialView, renderViewThe starting view, a view restored for the reader (it wins over defaultView), or the rows in a view other than the table
initialState, initialColumnState, initialDensityRestore state before the first request
setupRuns as a hook in its own component, for effects such as syncing
wrapBody, renderRow, renderAfterRowWrap or extend rows

Labels

English is the default. Pass labels={dataTableLabelsZhCN} for Chinese, or override individual entries; the locale entry also formats numbers and dates.

API

PropDescription
columnsColumn configuration.
dataLocal rows.
requestRemote rows: receives { page, pageSize, sort, keyword, search, filters, advanced, signal } and returns { data, total? }.
rowKeyRow identity, a key or a function. Required for selection, expansion and drag sorting.
pluginsFeatures beyond the core.
rowSelectiontrue, or { onChange, isDisabled }.
paginationfalse, or { pageSize, pageSizes }.
initialStateInitial page, pageSize, sort and query.
onStateChangeCalled with the state after each change.
title, toolbarToolbar heading and actions.
maxFiltersFilters on the toolbar row before the rest share a Filters button; defaults to 2.
chipsfalse (default); true lists active conditions as removable chips below the toolbar.
layoutfill (default) or auto.
responsiveCards on narrow screens; defaults to true.
loadingLoading state for local data.
accessColumn permissions by key: hidden or readonly.
labelsText overrides.
actionRefReceives { reload, reset }.
tableA table from useDataTable, instead of the options above.

The design draws on shadcn-admin tables for composable parts, Ant Design ProTable for column-driven search and requests, and motion tables for row transitions.