ValyroUI Русская версия

Data Table

Tables with search and sorting. Free, MIT · Data and metrics › Tables

Installation

npx valyro-cli@latest add data-table
npx shadcn@latest add https://valyro.xyz/r/data-table.json
npm install valyro-ui

import 'valyro-ui/styles.css';
import { DataTable } from 'valyro-ui';

Props

PropTypeDefault
datareadonly T[]All rows; search, sorting and pagination run on this array in the browser. Or rows as children (see children).
columnsreadonly DataTableColumn<T>[]Column definitions: header, value accessor, cell renderer, sorting, alignment and width.
childrenReactNodeThe compound form instead of data and columns: a DataTable.Header of DataTable.Columns and a DataTable.Body of DataTable.Rows with a DataTable.Cell per column. Search, sorting and selection work on the cells' value (or their text); onRowClick gets a DataTableRowData.
getRowId(row: T, index: number) => stringStable id for selection and keys. Defaults to row.id, then the row's index in data.
labelstringAccessible name of the table.
searchablebooleanfalseShows a search field that filters rows across all columns.
pageSizenumberRows per page. Omit to show every row.
sortSortState | nullControlled sort; use with onSortChange.
defaultSortSortState | nullnullInitial sort when uncontrolled.
onSortChange(sort: SortState | null) => voidCalled with the new sort when it changes.
selectablebooleanfalseAdds a checkbox column.
selectedstring[]Controlled selected; use with onSelectedChange.
defaultSelectedstring[][]Initial selected when uncontrolled.
onSelectedChange(ids: string[]) => voidCalled with the new selected when it changes.
onRowClick(row: T) => voidMakes rows clickable and focusable; Enter on a focused row calls it too.
loadingbooleanfalseSkeleton rows (pageSize or 5) replace the body, and the select-all and paging buttons are disabled.
density'comfortable' | 'compact''comfortable'Row height and text size: compact has tighter cells and smaller text.
maxHeightCSSProperties['maxHeight']Limits the height; the body scrolls under a pinned header.
virtualizebooleanfalseRenders only the rows scrolled into view, for thousands of rows without pagination. Needs maxHeight; rows should share one height (the first rendered row is measured).
stickyFirstColumnbooleantrueKeeps the first column (and the checkbox column) in view while scrolling sideways.
emptyReactNodeReplaces the default empty state.
localestringLocale for default number/date cells and counters. Defaults to the ThemeProvider locale, then the browser's.
labelsPartial<DataTableLabels>Overrides for the built-in English text; keys left out keep their defaults.

Compound parts

DataTable.Header (DataTableHeader), DataTable.Column (DataTableColumnPart), DataTable.Body (DataTableBody), DataTable.Row (DataTableRow), DataTable.Cell (DataTableCell)

Related components

Previous: Filter Toolbar · Next: Data Grid · All Data and metrics