Data table
Shows rows with search, filters, sorting, selection, and pagination.
Projects
data-table-demo.tsx
Installation
The CLI adds the files, packages, theme variables, and Tailwind plugin that this component uses. Before you run it, set up your project.
npm
yarn
pnpm
bun
Column filters
A filtered column also needs sortValue.
Invoices
Region
Status
data-table-column-filters-demo.tsx
Resizable columns and row actions
Set width on a column to set its starting width. onRowAction runs when a user clicks a row or presses Enter on it.
Support tickets
data-table-resizable-demo.tsx
API reference
vip/ui adds or changes the props below. For all other props, see React Aria Table (opens in a new tab).
DataTable
- label: stringRequired
- Names the table and its search and pagination controls.
- rows: readonly T[]Required
- All the rows. The table searches, filters, sorts, and pages them in the browser.
- columns: readonly DataTableColumn<T>[]Required
- Column definitions. The first column labels each row.
- getRowId: (row: T) => KeyRequired
- Returns a unique, stable key for each row.
- getSearchText: (row: T) => string
- Shows a search field. Return all the text that search can find in a row.
- pageSize: number = 5
- Rows on each page.
- selectable: boolean = true
- Shows a selection checkbox in each row. Select all selects only the rows on the current page.
- selectedKeys: Iterable<Key>
- The selected row keys, controlled. The selection stays when the page, search, or filters change.
- defaultSelectedKeys: Iterable<Key>
- The row keys that are selected at first, uncontrolled. Without it, no rows are selected.
- onSelectionChange: (keys: Set<Key>) => void
- Receives selected row keys, including keys on other pages.
- disabledKeys: Iterable<Key>
- Rows that cannot be selected or focused.
- onRowAction: (key: Key) => void
- Called when a user clicks a row or presses Enter on it. The checkbox still selects the row.
- resizable: boolean = false
- Adds a resize handle to each column header.
DataTableColumn
- id: stringRequired
- A stable key for the column.
- header: stringRequired
- The visible column header. A column filter uses it as its label.
- cell: (row: T) => ReactNodeRequired
- Renders the cell for a row.
- sortValue: (row: T) => string | number
- Turns on sorting for the column. Return a string or a number. Column filters use this value too.
- align: "start" | "end" = "start"
- Aligns the header and cells. Use end for numbers.
- width: number | string
- Starting width in pixels, a percentage, or a fraction such as "2fr".
- minWidth: number | string
- Smallest width the column can resize to.
- filter: { type: "text" } | { type: "select"; options: readonly SelectOption[] }
- Adds a text or single-choice filter for a column with sortValue. Filters combine with search before sorting and pagination.