Data table
Requires 2.0
This page describes the TanStack Table 9 DataTable in @rtorcato/shadcn-ui
2.0.0 and later. 1.x ships the TanStack Table 8 version; see
Upgrading from 1.x.
A generic table built on @tanstack/react-table:
sorting, pagination, and a column-visibility dropdown out of the box. Exports
ColumnDef so you can define columns without a separate import. It is bound to
the table's feature set (DataTableFeatures), so import it from here rather than
from @tanstack/react-table.
import { DataTable, type ColumnDef } from '@rtorcato/shadcn-ui/components/ui-extended/data-table'
Usage
type Payment = { id: string; amount: number; status: string }
const columns: ColumnDef<Payment>[] = [
{ accessorKey: 'status', header: 'Status' },
{ accessorKey: 'amount', header: 'Amount' },
]
<DataTable columns={columns} data={payments} pageSize={10} />
Props
| Prop | Type | Default | Description |
|---|---|---|---|
columns | ColumnDef<TData>[] | — | TanStack Table 9 column definitions, bound to DataTableFeatures. |
data | TData[] (TData extends RowData) | — | Rows to render. |
pageSize | number | 10 | Rows per page. |
className | string | — | Wrapper class. |
Upgrading from 1.x
DataTable runs on TanStack Table 9 from @rtorcato/shadcn-ui 2.0.0. Plain
accessor/header/cell columns typed with
ColumnDef from this module keep working unchanged. Check these if you go further:
@tanstack/react-tableis now^9(a runtime dependency of@rtorcato/shadcn-ui). Types you import straight from it must also come from v9.ColumnDefis DataTable's own alias, bound toDataTableFeatures. Columns typed with TanStack's ownColumnDef, or built withcreateColumnHelperfor another feature set, are not assignable.TDatamust extendRowData(Record<string, any> | any[]). Primitive orunknownrows no longer type-check.- v9 renames:
sortingFn→sortFn,getSortingFn→getSortFn,SortingFn→SortFn,VisibilityState→ColumnVisibilityState. ColumnMeta/TableMetaaugmentation takesTFeaturesas the first generic.- Rows no longer carry a
data-state="selected"attribute. No row-selection feature is registered, and it always rendered"false"before.