DS0
Patterns

Data Table

A full-featured data table with search, sorting, pagination, and row selection.

Overview

The DataTable recipe provides a generic, fully-typed data table with search filtering, column sorting, pagination, row selection with checkboxes, loading skeletons, and empty state display.

Usage

import { DataTable } from '@/recipes/data-table';

<DataTable
  columns={[
    { key: 'name', header: 'Name', accessor: (row) => row.name, sortable: true },
    { key: 'email', header: 'Email', accessor: (row) => row.email },
    { key: 'role', header: 'Role', accessor: (row) => row.role, sortable: true },
  ]}
  data={users}
  getRowKey={(row) => row.id}
  searchable
  selectable
  pageSize={10}
/>

API Reference

PropTypeDefaultDescription
columnsDataTableColumn<T>[]Column definitions
dataT[]Data rows
getRowKey(row: T) => stringUnique key accessor
searchablebooleanfalseEnable search
searchPlaceholderstring'Search…'Search placeholder
onSearch(query: string) => T[]Custom search filter
selectablebooleanfalseEnable row selection
selectedKeysSet<string>new Set()Selected row keys
onSelectionChange(keys: Set<string>) => voidSelection change handler
pageSizenumberEnable pagination
isLoadingbooleanfalseLoading skeleton state
emptyMessagestring'No results found.'Empty state text
classNamestringAdditional CSS classes

DataTableColumn

interface DataTableColumn<T> {
  key: string;
  header: string;
  accessor: (row: T) => ReactNode;
  sortable?: boolean;
  width?: string;
}

On this page