Skip to main content

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​

PropTypeDefaultDescription
columnsColumnDef<TData>[]—TanStack Table 9 column definitions, bound to DataTableFeatures.
dataTData[] (TData extends RowData)—Rows to render.
pageSizenumber10Rows per page.
classNamestring—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:

  1. @tanstack/react-table is now ^9 (a runtime dependency of @rtorcato/shadcn-ui). Types you import straight from it must also come from v9.
  2. ColumnDef is DataTable's own alias, bound to DataTableFeatures. Columns typed with TanStack's own ColumnDef, or built with createColumnHelper for another feature set, are not assignable.
  3. TData must extend RowData (Record<string, any> | any[]). Primitive or unknown rows no longer type-check.
  4. v9 renames: sortingFn → sortFn, getSortingFn → getSortFn, SortingFn → SortFn, VisibilityState → ColumnVisibilityState.
  5. ColumnMeta / TableMeta augmentation takes TFeatures as the first generic.
  6. Rows no longer carry a data-state="selected" attribute. No row-selection feature is registered, and it always rendered "false" before.