Data Table
TanStack table with sorting, search & faceted filters, pagination, row selection with bulk actions, column visibility, density, and loading/empty/error states.
Import
import { DataTable } from "@cooud-ui/ui";
npx cooud-ui add data-table
Examples
API Reference
Generated from the component's exported types.
DataTableProps
| Prop | Type | Default | Description |
|---|---|---|---|
columns* | ColumnDef<TData, TValue>[] | — | — |
data* | TData[] | — | — |
searchable | boolean | — | Show the toolbar with a global search field. |
searchPlaceholder | string | — | Placeholder for the global search field. Defaults to "Search…". |
globalFilter | string | — | Controlled global filter value. Implies a controlled toolbar search. |
onGlobalFilterChange | OnChangeFn<string> | — | Called when the global filter changes (controlled or uncontrolled). |
facetedFilters | DataTableFacetedFilter[] | — | Faceted (multi-select) column filters rendered in the toolbar. |
toolbarStart | ReactNode | — | Extra nodes rendered on the left side of the toolbar. |
toolbarEnd | ReactNode | — | Extra nodes rendered on the right side of the toolbar (before the View menu). |
enableColumnVisibility | boolean | — | Show the "View" menu that toggles column visibility. |
columnVisibility | VisibilityState | — | Controlled column visibility state. |
onColumnVisibilityChange | OnChangeFn<VisibilityState> | — | Called when column visibility changes. |
sorting | SortingState | — | Controlled sorting state. |
onSortingChange | OnChangeFn<SortingState> | — | Called when sorting changes. |
manualSorting | boolean | — | Server-side sorting: skip the client sort model. |
columnFilters | ColumnFiltersState | — | Controlled column filters state. |
onColumnFiltersChange | OnChangeFn<ColumnFiltersState> | — | Called when column filters change. |
manualFiltering | boolean | — | Server-side filtering: skip the client filter model. |
pagination | boolean | — | Show the pagination footer. |
paginationState | PaginationState | — | Controlled pagination state. |
onPaginationChange | OnChangeFn<PaginationState> | — | Called when pagination changes (controlled). |
manualPagination | boolean | — | Server-side pagination: provide `pageCount` or `rowCount`. |
pageCount | number | — | Total page count for server-side pagination. |
rowCount | number | — | Total row count for server-side pagination (used to derive `pageCount`). |
initialPageSize | number | — | Initial page size when uncontrolled. Defaults to 10. |
pageSizeOptions | number[] | — | Page-size options offered in the footer select. Defaults to [10, 20, 30, 50]. |
enableRowSelection | boolean | ((row: Row<TData>) => boolean) | — | Render a leading checkbox column with header select-all. |
rowSelection | RowSelectionState | — | Controlled row-selection state. |
onRowSelectionChange | OnChangeFn<RowSelectionState> | — | Called when row selection changes. |
bulkActions | (rows: Row<TData>[]) => ReactNode | — | Render slot for bulk actions. Receives the currently selected rows; shown in a bar above the table only while at least one row is selected. |
density | DataTableDensity | — | Controlled cell padding density. When provided, the toolbar toggle becomes controlled and you must update it via . Omit it to let the table manage density internally (see ). |
onDensityChange | (density: DataTableDensity) => void | — | Called when the density toggle is pressed (controlled or uncontrolled). |
initialDensity | DataTableDensity | — | Initial density when uncontrolled. Defaults to "comfortable". |
enableDensityToggle | boolean | — | Show a comfortable/compact density toggle in the toolbar. |
enableCsvExport | boolean | — | Show a CSV export button in the toolbar. |
csvFileName | string | — | Download file name (without extension). Defaults to "export". |
loading | boolean | — | Render skeleton rows instead of data. |
loadingRowCount | number | — | Number of skeleton rows while `loading`. Defaults to the page size or 5. |
error | ReactNode | — | Render an error state with an optional retry button. |
onRetry | () => void | — | Called when the error-state retry button is pressed. |
emptyState | ReactNode | — | Custom empty-state content. Defaults to "No results.". |
className | string | — | Class applied to the outer wrapper. |
toolbarLabel | string | — | Accessible label for the toolbar region. Defaults to "Table controls". |
DataTableColumnHeaderProps
| Prop | Type | Default | Description |
|---|---|---|---|
column* | Column<TData, TValue> | — | — |
title* | string | — | — |
className | string | — | — |