cnippet/ui
  1. ui
  2. data
  3. data table

data

Data Table

Sortable, filterable, paginated tables with row selection, built on TanStack Table v9 and the Cnippet Table. Copy-paste ready.

API Reference

Installation

Usage

TanStack Table v9 only adds a feature's state and APIs when you register it, so start by listing the features this table uses. Keep features, columns and static data outside the component so they aren't rebuilt on every render.

Anatomy

Good to know

  • Each part checks its features at compile time. For example, passing a table without rowPaginationFeature to DataTablePagination is a type error, not a runtime crash.
  • DataTable renders whatever the table produces: visible columns, sorted, filtered and paginated rows, and expanded sub-rows. It doesn't add any behavior on its own.
  • The parts subscribe to their own state slice, so they stay current even if you pass a narrow selector to useTable, and they work with the React Compiler.
  • Give rows a stable id with getRowId: (row) => row.id. Selection is keyed by row id, and the default index-based ids change when rows are sorted, filtered or removed.
  • Selection is separate from data. After deleting selected rows, clear it with table.resetRowSelection(true).
  • For a faceted filter, set the column's filterFn: "arrHas" and register filterFn_arrHas. It keeps rows whose value equals any selected option. Register columnFacetingFeature with facetedRowModel and facetedUniqueValues to show a count next to each option.
  • Shift-click a row checkbox to select a range.

API Reference

DataTable

Renders the table's header groups and current rows using Table. Rows that are selected get data-state="selected", and sortable headers get aria-sort.

Other props go on the <table> element.

DataTableColumnHeader

A header button that cycles the column's sort and shows its direction. Renders plain text when the column can't sort. Requires rowSortingFeature.

DataTableSelectAll / DataTableRowCheckbox

Checkboxes for the header and for each row. The header checkbox selects every row on the current page and shows an indeterminate state when only some are selected. Requires rowSelectionFeature.

DataTableSearch

A search input bound to the global filter. Requires columnFilteringFeature, globalFilteringFeature and filteredRowModel, plus a globalFilterFn such as "includesString".

DataTableFacetedFilter

A menu of checkbox options that filters one column, with the selection shown on the trigger. Requires columnFilteringFeature and the column's filterFn: "arrHas".

DataTableViewOptions

A menu for showing and hiding columns that allow it. Labels come from string headers, falling back to the column id. Requires columnVisibilityFeature.

DataTablePagination

Row count (or selected count when rowSelectionFeature is registered), a rows-per-page select, and first, previous, next and last page buttons. Requires rowPaginationFeature and paginatedRowModel.

Examples

Sorting

Click a header to sort; click again to reverse. The table starts sorted by issue date, newest first.

Search and pagination

A global search across customer name, email and company, with page size controls. The empty message appears when nothing matches.

Row selection

Select rows to reveal bulk actions, Shift-click to select a range, and remove the selected members. The owner's row can't be selected.

Column visibility

Secondary columns start hidden; the View menu shows or hides any column that allows it.

Faceted filters

Filter issues by status and priority, with a live count next to each option and a Reset button when any filter is active.

Expandable rows

Nested data via getSubRows, with a toggle per parent row and expand/collapse all.

Row actions

A card-style table with a menu of actions on each row. The actions update component state through the table's meta option.