Join our Discord Community

Data Table

React data table with sorting, filtering, pagination, and selection. Built with TanStack Table for powerful data management and user interactions.

Displaying data in tables? This component handles the complex stuff - sorting columns, filtering rows, selecting items, and paginating large datasets. Perfect for admin panels, dashboards, and anywhere you need to show structured data.

Loading component...

Built on TanStack Table - the most powerful table library for React.

npx shadcn@latest add table
npm install @tanstack/react-table

Why this data table rocks

TanStack Table gives you enterprise-level features without the complexity:

  • Click to sort any column - Users expect this, and it just works
  • Search and filter data - Global search plus column-specific filters
  • Select rows with checkboxes - Bulk actions made easy
  • Handle huge datasets - Pagination and virtualization built-in
  • Show/hide columns - Let users customize their view
  • Fully accessible - Screen readers and keyboard navigation covered
  • TypeScript native - Catch data errors at compile time

Data table patterns you need

Basic data display

Just show the data, clean and simple:

Loading component...

Sortable columns

Click any header to sort - exactly what users expect:

Loading component...

Search and filter

Users need to find specific rows quickly:

Loading component...

Break up large datasets

Pagination keeps things fast and manageable:

Loading component...

Multi-select with checkboxes

Bulk actions need row selection:

Loading component...

Show/hide columns

Let users customize which columns they see:

Loading component...

What components are available?

Table Components

The basic building blocks for any table:

ComponentWhat it does
TableMain container - handles responsive scrolling
TableHeaderWhere column headers live
TableBodyContains all your data rows
TableFooterSummary rows, totals, etc.
TableRowIndividual row with hover and selection styling
TableHeadColumn header cells
TableCellRegular data cells
TableCaptionAccessible description of the table

Column Definition

Define what each column shows and how it behaves:

const columns: ColumnDef<YourDataType>[] = [
  {
    accessorKey: "propertyName",        // Which data field to show
    header: "Display Name",             // Column title
    cell: ({ row }) => <CustomCell />,  // Custom formatting
    enableSorting: true,                // Clickable to sort?
    enableHiding: true,                 // Can users hide it?
    enableFiltering: true,              // Include in search?
  },
]

Table Configuration

The main hook that powers everything:

const table = useReactTable({
  data,                               // Your array of data
  columns,                            // Column definitions
  getCoreRowModel: getCoreRowModel(), // Always required
  
  // Add features as needed:
  getSortedRowModel: getSortedRowModel(),     // For sorting
  getFilteredRowModel: getFilteredRowModel(), // For search/filters
  getPaginationRowModel: getPaginationRowModel(), // For pagination
  
  // Connect your state:
  state: { sorting, columnFilters, rowSelection },
  onSortingChange: setSorting,
  onColumnFiltersChange: setColumnFilters,
})

Data table best practices

What works best for real applications:

  • Start simple, add features gradually - Basic table first, then sorting, then filters
  • Always handle empty states - Show helpful messages when there's no data
  • Make loading obvious - Users need to know when data is being fetched
  • Keep column headers clear - "Email Address" is better than just "Email"
  • Use consistent data types - Don't mix strings and numbers in the same column
  • Implement keyboard navigation - Tab through controls, Enter to activate
  • Test with real data volumes - Performance changes dramatically with 1000+ rows
  • Consider mobile users - Tables get cramped, maybe show fewer columns on small screens