ZUI

Search documentation

Find a page or a heading.

Data Table

The composable parts of a @tanstack/react-table view - toolbar, view, pagination and view options - reading one shared table instance from context.

tsx

Installation

bash

Usage

tsx

The consumer owns useReactTable and the column defs; this family ships only the composable parts:

tsx

Give a column a sortable, hideable header with Data Table Column Header.

Composition

text

API reference

DataTable

Renders a div and takes every prop a div takes, plus:

Holds the @tanstack/react-table instance in context, so every part reads it without prop-drilling. It sets data-slot="data-table".

DataTableToolbar

Renders a div and takes every prop a div takes. A flex row for filters and actions above the table. It sets data-slot="data-table-toolbar".

DataTableView

Renders a div and takes every prop a div takes. Renders the table's header and body from the context table instance, in a bordered frame that scrolls sideways when the columns are wider than it. Its children render in the body only while there are no rows - a DataTableEmpty. It sets data-slot="data-table-view".

DataTableEmpty

Renders shadcn's TableCell and takes every prop it takes. The one row a DataTableView shows when there are no rows: a cell spanning every column, its children centred in an upstream Empty. It defaults colSpan to the table's leaf column count. The cell keeps TableCell's whitespace-nowrap, so a long message widens the table rather than wrapping; keep it short. It sets data-slot="data-table-empty".

useDataTable

useDataTable<TData>(): TanstackTable<TData> - reads the @tanstack/react-table instance the surrounding DataTable provides; throws outside one.

DataTablePagination

Renders a div and takes every prop a div takes. A right-aligned flex row for the pager; children are its content, such as a status line and the step buttons, which read the table themselves. It sets data-slot="data-table-pagination".

DataTablePaginationPrevious

Renders shadcn's Button and takes every prop it takes except children, plus:

Steps the table back one page, disabled on the first; its animated chevron plays while it is hovered or focused. It sets data-slot="data-table-pagination-previous".

DataTablePaginationNext

Renders shadcn's Button and takes every prop it takes except children, plus:

Steps the table on one page, disabled on the last; its animated chevron plays while it is hovered or focused. It sets data-slot="data-table-pagination-next".

DataTableViewOptions

Renders shadcn's Button and takes every prop it takes. A column-visibility toggle reading the table from DataTable context: icon-only by default, named "Toggle columns" unless an aria-label is given, and renders nothing when no column can hide. It sets data-slot="data-table-view-options".