Shadcn React Table

Search documentation

Search the docs

Server-side data

When your data lives on a server, hand pagination, sorting, and filtering off to it. All TanStack manual* flags pass through.

Server-side (manual)Manual pagination against a simulated server.
GitHub
ID
AvaThompsonOwnerEngineeringactive22$45,000Jan 2, 2023
0%
LiamNguyenAdminMarketinginactive25$47,137Jan 13, 2023
9%
NoahSilvaEditorDesignpending28$49,274Jan 24, 2023
18%
EmmaCarterViewerSalesactive31$51,411Feb 4, 2023
27%
OliviaRossiOwnerSupportinactive34$53,548Feb 15, 2023
36%
WilliamWalkerAdminEngineeringpending37$55,685Feb 26, 2023
45%
SophiaPatelEditorMarketingactive40$57,822Mar 9, 2023
54%
JamesMullerViewerDesigninactive43$59,959Mar 20, 2023
63%
IsabellaParkOwnerSalespending46$62,096Mar 31, 2023
72%
LucasReyesAdminSupportactive49$64,233Apr 11, 2023
81%
$546,165
Rows per page
1–10 of 95

Server pagination

Set manualPagination: true, supply the total rowCount, control state.pagination, and handle onPaginationChange. Use isLoading to show a loading state while fetching.

tsx
import { useState } from "react"
import { DataTable, useDataTable } from "@/components/ui/data-table"

const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 10 })
const { data, rowCount, isFetching } = useUsers(pagination)

const table = useDataTable({
  data,
  columns,
  getRowId: (row) => row.id,
  manualPagination: true,
  rowCount,
  state: { pagination },
  onPaginationChange: setPagination,
  isLoading: isFetching,
})

return <DataTable table={table} />

Server sorting and filtering

The same pattern applies to other operations:

  • Sorting: manualSorting: true + state.sorting + onSortingChange.
  • Filtering: manualFiltering: true + state.columnFilters / globalFilter.
tsx
const table = useDataTable({
  data,
  columns,
  getRowId: (row) => row.id,
  manualSorting: true,
  state: { sorting },
  onSortingChange: setSorting,
  manualFiltering: true,
})

Facets are not auto-computed

In manual filtering, faceted option lists and min/max values are not computed from the data — the server supplies the rows, so you must provide facet options yourself if you use them.

With React Query

Keep the table's pagination, sorting and search in React state, put them in the query key, and pass the result back as data and rowCount. placeholderData: keepPreviousData keeps the current page on screen while the next one loads; showProgressBars follows isFetching.

React QueryServer-side paging, sorting and search with React Query.
GitHub
Loading…
ID
$0
Rows per page
0–0 of 0

Columns from the data

When the columns depend on the response, build them with useMemo from the data's fields, so they change only when the data does.

Dynamic columnsColumns generated from the fetched data's fields.
GitHub
Loading…