Data Table
Explore the Data Table component and try its interactive examples.
Preview
Installation
Install the component source via shadcn Registry, the BIU CLI, or as an npm package.
pnpm dlx shadcn add @biudev/data-tableFirst time using @biudev? Map "@biudev": "https://ui.biu.dev/r/0.1.0/{name}.json" under registries in your components.json (see setup).
Usage
Start with this example, then adjust the import path for your project.
"use client";
import { DataTable } from "@/components/ui/biu/data-table";
export function Example() {
const rows = [
{ id: "1", customer: "Maya Labs", status: "Paid", amount: 240 },
{ id: "2", customer: "Nordic Cloud", status: "Pending", amount: 1200 },
];
return (
<DataTable
data={rows}
searchable
selectable
columnVisibility
pageSize={5}
columns={[
{ key: "customer", header: "Customer", sortable: true },
{ key: "status", header: "Status", sortable: true },
{ key: "amount", header: "Amount", sortable: true, align: "right", cell: (row) => `$${row.amount}` },
]}
/>
);
}Examples
Try each example or switch to its code.
API reference
Properties and defaults from the component source. An asterisk marks a required property; a dash means no explicit default.
DataTableSortDirection
Also accepts properties from 'asc' & 'desc'.
Some properties depend on the variant; consult the source for the full union.
'asc' | 'desc'DataTableSort
Also accepts properties from null.
Some properties depend on the variant; consult the source for the full union.
| Property | Type | Default | Description |
|---|---|---|---|
key (varies) | string | — | Unique key identifying this column, series, or record. |
direction (varies) | DataTableSortDirection | — | Primary layout or sort direction. |
DataTableColumn
| Property | Type | Default | Description |
|---|---|---|---|
key * | string | — | Unique key identifying this column, series, or record. |
header * | React.ReactNode | — | Header label or custom header element. |
label | string | — | Visible text label or accessible name. |
accessor | (row: T) => unknown | — | Extract raw value for default cell rendering, sorting, and search filtering. |
searchValue | (row: T) => string | — | Extract searchable text when a custom cell renders extra fields (e.g. email under name). |
cell | (row: T, index: number) => React.ReactNode | — | Custom cell renderer receiving the current row. |
sortable | boolean | — | Enables click-to-sort interaction on this column. |
sortFn | (a: T, b: T) => number | — | Custom comparator function used when sorting this column. |
hideable | boolean | — | Whether the column can be hidden from the Columns menu. |
defaultHidden | boolean | — | Starts the column hidden until toggled visible by the user. |
align | 'left' | 'center' | 'right' | — | Alignment relative to the anchor or column cells. |
width | number | string | — | Explicit CSS width of the sidebar or column. |
DataTableFilterOption
| Property | Type | Default | Description |
|---|---|---|---|
value * | string | — | Controlled current value. |
label * | string | — | Visible text label or accessible name. |
DataTableFilter
| Property | Type | Default | Description |
|---|---|---|---|
key * | string | — | Unique key identifying this column, series, or record. |
label * | string | — | Visible text label or accessible name. |
options * | DataTableFilterOption[] | — | Available selectable options. |
accessor | (row: T) => string | string[] | — | Extracts the facet value from a row for filtering. |
DataTableLabels
| Property | Type | Default | Description |
|---|---|---|---|
clearSearch * | string | — | Accessible label for clearing the search query. |
clearFilter * | string | — | Label for clearing an active facet filter. |
resetFilters * | string | — | Label for resetting all active search and facet filters. |
columns * | string | — | Column definitions configuring headers, cells, and sorting. |
showAllColumns * | string | — | Label for restoring all hidden columns. |
selected * | string | — | Whether this item or surface is currently selected. |
clearSelection * | string | — | Label for clearing all selected rows. |
selectAllOnPage * | string | — | Accessible label for selecting every row on the current page. |
deselectAllOnPage * | string | — | Accessible label for deselecting rows on the current page. |
selectRow * | (id: string) => string | — | Formatter returning the accessible checkbox label for a row. |
toggleColumnsMenu * | string | — | Accessible label for the column visibility toggle button. |
filterMenu * | (label: string) => string | — | Formatter returning the accessible label for a filter menu. |
filterOptionsMenu * | (label: string) => string | — | Formatter returning the accessible label for filter options. |
DataTableProps
| Property | Type | Default | Description |
|---|---|---|---|
data * | T[] | — | Array of data records rendered by the table or chart. |
columns * | DataTableColumn<T>[] | — | Column definitions configuring headers, cells, and sorting. |
getRowId | (row: T, index: number) => string | — | Stable unique row ID extractor. Defaults to row.id, or stable object identity when id is omitted. |
searchable | boolean | false | Displays a search input in the table toolbar. |
searchPlaceholder | string | 'Search…' | Placeholder text inside the table search input. |
search | string | — | Controlled search query string. |
defaultSearch | string | '' | Initial uncontrolled search query. |
onSearchChange | (value: string) => void | — | Callback invoked when the search query changes. |
filters | DataTableFilter<T>[] | — | Facet filter definitions rendered in the table toolbar. |
sort | DataTableSort | — | Controlled sort column key and direction. |
defaultSort | DataTableSort | null | Initial uncontrolled sort state. |
onSortChange | (sort: DataTableSort) => void | — | Callback invoked when column sorting changes. |
selectable | boolean | false | Adds row selection checkboxes to the table. |
selectedIds | string[] | — | Controlled array of selected row IDs. |
defaultSelectedIds | string[] | [] | Initial uncontrolled selected row IDs. |
onSelectionChange | (ids: string[]) => void | — | Callback invoked when selected row IDs change. |
selectionActions | (selectedRows: T[], clearSelection: () => void) => React.ReactNode | — | Bulk action controls shown when one or more rows are selected. |
columnVisibility | boolean | false | Shows a Columns menu to toggle column visibility. |
hiddenColumns | string[] | — | Controlled list of hidden column keys. |
defaultHiddenColumns | string[] | — | Initial uncontrolled list of hidden column keys. |
onHiddenColumnsChange | (keys: string[]) => void | — | Callback invoked when column visibility changes. |
paginate | boolean | true | Enables client-side pagination controls below the table. |
pageSize | number | 5 | Number of rows per page. Updates when the prop changes. |
pageSizes | number[] | [5, 10, 25] | Selectable page-size options shown in the pagination control. |
page | number | — | Current 1-based page number. |
onPageChange | (page: number) => void | — | Callback invoked when the active page changes. |
onPageSizeChange | (size: number) => void | — | Callback invoked when the page size changes. |
paginationLabels | Partial<PaginationLabels> | — | Localized label overrides forwarded to the pagination bar. |
labels | Partial<DataTableLabels> | — | Override built-in UI strings for any language or i18n library. |
locale | string | — | BCP 47 locale used for both locale-aware sorting and Pagination number formatting. |
density | 'compact' | 'default' | 'comfortable' | 'default' | Row vertical padding density. |
stickyHeader | boolean | false | Pin the table header inside the table scroll container (pair with maxHeight for vertical scrolling). |
maxHeight | number | string | — | Maximum height before internal scrolling activates. |
toolbarExtra | React.ReactNode | — | Extra controls rendered at the trailing end of the toolbar. |
emptyTitle | React.ReactNode | 'No results found' | Heading shown when the table has no matching rows. |
emptyDescription | React.ReactNode | 'Try adjusting your search or filter criteria.' | Supporting message shown in the empty table state. |
onRowClick | (row: T) => void | — | Callback invoked when a table body row is clicked. |
className | string | — | Additional CSS class name applied to the root element. |
style | React.CSSProperties | — | Inline CSS styles applied to the root element. |
'aria-label' | string | 'Data table' | Accessible label for assistive technologies. |
Source
Review a formatted version of the component source used by the Registry.