Data Table

A powerful data table component built on TanStack Table for sorting, filtering, and row selection.

Preview

Installation

Usage

Architecture

DataTable uses a composition-based architecture. The root DataTable component provides context to child components, allowing you to compose the exact table structure you need.

Examples

Sorting

Enable column sorting with the enableSorting prop on DataTable, then pass enableSorting to DataTableHeader to render sort controls. Columns with string headers automatically render clickable sort buttons with direction indicators.

Row Selection

Enable row selection with the enableRowSelection prop. Checkboxes are automatically added as the first column. Control selection state with rowSelection and onRowSelectionChange.

0 of 5 row(s) selected.

Toolbar

Add a toolbar with search and column toggles by composing DataTableToolbar with DataTableSearch and DataTableColumnToggle. Enable enableFiltering on DataTable for search to work. This example also demonstrates sorting and row selection.

Striped

Use the striped prop on DataTableContent for alternating row backgrounds.

Column Definitions

Define columns using the ColumnDef type from TanStack Table. Each column can have:

  • accessorKey - The key to access data from the row
  • header - Header content (string or render function)
  • cell - Cell content render function
  • enableSorting - Whether the column is sortable (default: true when enableSorting prop is set)

When enableSorting is enabled, columns with string headers automatically render a sortable button with direction indicators. Use meta.align to control header alignment, or a render function for fully custom headers.

API Reference

DataTable

Root component that creates the TanStack Table instance and provides context to children.

Prop

DataTableToolbar

Container for toolbar controls. Renders above the table content with visual connection to the header.

Prop

DataTableSearch

Search input that filters across all columns using the global filter.

Prop

DataTableColumnToggle

Dropdown button that allows users to show/hide columns.

This component has no configurable props. It automatically reads column visibility state from the DataTable context.

DataTableContent

Wrapper for the table that applies styling props. Accepts all Table component props.

Prop

DataTableHeader

Renders the table header with optional sort controls.

Prop

DataTableBody

Renders the table body with support for empty state.

Prop

DataTablePagination

Pagination controls with previous/next buttons and selection count.

Prop

DataTableToolbarSeparator

Visual separator for toolbar items. No configurable props.