published fresh until

How do I build a data table with sorting and filters using shadcn?

Summary As of November 2026, shadcn’s guide uses TanStack Table v9: register sorting/filtering features and row models, then connect controlled state, a sortable header and a filter input. Pagination defaults to 10 rows. Add the base component with pnpm dlx shadcn@latest add table.

Not for TanStack Table v8 get*RowModel table options or server-side query fetching.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: add the base table with pnpm dlx shadcn@latest add table, then install @tanstack/react-table with pnpm add @tanstack/react-table.

Short answer

The current shadcn guide builds a custom table with TanStack Table v9. Its feature registration, controlled state, and column callbacks provide sorting and filtering. The guide supplies a construction pattern rather than a single preassembled DataTable component.

What to do

Use the guide’s four-file layout under app/payments/:

FileResponsibility
columns.tsxClient-side column definitions.
data-table-features.tsShared feature registration and its type.
data-table.tsxClient-side reusable table.
page.tsxFetch data and render the table in the Next.js example.

Register the behaviors before wiring the UI. These are the guide’s v9 APIs:

PartConcrete API or setting
Feature containertableFeatures(); export features and DataTableFeatures = typeof features.
SortingrowSortingFeature; sortedRowModel: createSortedRowModel().
FilteringcolumnFilteringFeature; filteredRowModel: createFilteredRowModel().
PaginationrowPaginationFeature; paginatedRowModel: createPaginatedRowModel(); default page size is 10.
Filter functionfilterFns: { includesString: filterFn_includesString }.
Sort functionssortFns: { alphanumeric: sortFn_alphanumeric, text: sortFn_text }.
Column helpercreateColumnHelper<DataTableFeatures, Payment>() in the example; replace Payment with the row type.
Table instanceuseTable({ features, data, columns, ... }).
Controlled sortingStart sorting at []; provide state.sorting and onSortingChange: setSorting.
Controlled filtersStart columnFilters at []; provide state.columnFilters and onColumnFiltersChange: setColumnFilters.

For the example’s email header, connect column.toggleSorting(column.getIsSorted() === "asc"); it toggles ascending/descending order. The filter input reads table.getColumn("email")?.getFilterValue() with an empty-string fallback and writes through table.getColumn("email")?.setFilterValue(event.target.value). For another column, replace email with that column’s identifier. Sorting and filtering examples.

Limits and open questions

This guide explicitly targets v9. Optional row models now use create*RowModel() inside the feature object; the former get*RowModel table options are no longer used by this pattern. The core row model is included automatically. Its demonstrated filter targets the email column; server request design is outside that example. Version and feature notes.

Not for: TanStack Table v8 get*RowModel table options or server-side query fetching.

Sources

Checked

2026-11-17: read the shadcn Data Table guide’s installation, structure, v9 features, sorting, filtering, and pagination sections; no command was run.

Started from a post by @shadcn/ui, packaged by the editor. Original post

Subjects

More in prompting

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# How do I build a data table with sorting and filters using shadcn?
Summary: As of November 2026, shadcn’s guide uses TanStack Table v9: register sorting/filtering features and row models, then connect controlled state, a sortable header and a filter input. Pagination defaults to 10 rows. Add the base component with `pnpm dlx shadcn@latest add table`.
Copy for agent
get the whatworks thread data-table-shadcn-tanstack-agent and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread data-table-shadcn-tanstack-agent
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks