Examples
Server-side data
Hand the grid a dataSource and it sends one query object — page, sort, filters, quick filter — on every change, cancels the request it replaces, and renders the page and total your API returns.
Live demo
Server-side data
Change the sort and watch the request · Filter a column · Type in the quick filter · Page forward while a request is in flight
import { useState } from "react"
import { ProGrid, aggregate, evalColumnFilter, type DataSource, type ProColumnDef } from "@/components/pro-grid"
import { formatCurrency, operationOrders, type OperationOrder } from "@/lib/operations-data"
function StatusCell({ value }: { value: unknown }) {
const status = String(value)
return <span className={`order-status order-status--${status.toLowerCase().replaceAll(" ", "-")}`}>{status}</span>
}
const baseColumns: ProColumnDef<OperationOrder>[] = [
{ accessorKey: "id", header: "Order", size: 118, meta: { label: "Order", type: "string" } },
{ accessorKey: "customer", header: "Customer", size: 190, meta: { label: "Customer", type: "string" } },
{
accessorKey: "region",
header: "Region",
size: 145,
meta: {
label: "Region",
type: "string", filterVariant: "set",
filterOptions: ["North America", "Europe", "Asia Pacific", "Latin America"],
groupable: true,
pivotable: true,
},
},
{
accessorKey: "status",
header: "Status",
size: 120,
cell: ({ getValue }) => <StatusCell value={getValue()} />,
meta: {
label: "Status",
type: "string", filterVariant: "set",
filterOptions: ["On track", "At risk", "Delayed", "Complete"],
groupable: true,
pivotable: true,
},
},
{
accessorKey: "units",
header: "Units",
size: 88,
meta: { label: "Units", type: "number", align: "right", aggregable: true, defaultAgg: "sum" },
},
{
accessorKey: "revenue",
header: "Revenue",
size: 128,
meta: {
label: "Revenue",
type: "number",
align: "right",
aggregable: true,
defaultAgg: "sum",
formatValue: (value) => formatCurrency(Number(value)),
},
},
]
function abortableDelay(signal: AbortSignal) {
return new Promise<void>((resolve, reject) => {
const timer = window.setTimeout(resolve, 420)
signal.addEventListener("abort", () => {
window.clearTimeout(timer)
reject(new DOMException("Request aborted", "AbortError"))
}, { once: true })
})
}
const demoDataSource: DataSource<OperationOrder> = async (query, signal) => {
await abortableDelay(signal)
const search = query.quickFilter.trim().toLowerCase()
let rows = operationOrders.filter((row) => {
if (search && ![row.id, row.customer, row.region, row.status].some((value) => value.toLowerCase().includes(search))) return false
return query.filters.every((filter) => evalColumnFilter(row[filter.id], filter))
})
// Grand totals over everything the filters matched — before sorting and
// paging, which is what makes them the same on every page. Only computed
// when asked: the grid asks on the first load and whenever filters or
// aggregations change, not on a page or sort change.
const aggregates = query.aggregates?.length
? Object.fromEntries(query.aggregates.map((a) => [a.id, aggregate(a.fn, rows.map((row) => row[a.id]))]))
: undefined
rows = [...rows].sort((a, b) => {
for (const sort of query.sort) {
const left = a[sort.id]
const right = b[sort.id]
const result = typeof left === "number" && typeof right === "number"
? left - right
: String(left ?? "").localeCompare(String(right ?? ""))
if (result) return sort.desc ? -result : result
}
return 0
})
const start = query.page * query.pageSize
return { rows: rows.slice(start, start + query.pageSize), total: rows.length, ...(aggregates ? { aggregates } : {}) }
}
export function ServerDataDocsDemo() {
const [query, setQuery] = useState("Waiting for the first query…")
return (
<>
<div className="docs-demo__status" aria-live="polite">
<span>Mock API · 420 ms latency</span>
<code>{query}</code>
</div>
<ProGrid<OperationOrder>
columns={baseColumns}
dataSource={demoDataSource}
getRowId={(row) => row.id}
height={370}
onQueryChange={(next) => setQuery(`page=${next.page + 1} · size=${next.pageSize} · sort=${next.sort.length} · filters=${next.filters.length} · aggregates=${next.aggregates?.length ?? 0}`)}
pagination={{ pageSize: 8, pageSizeOptions: [8, 16, 24] }}
serverOperators
title="Server order queue"
/>
</>
)
}// The grid hands the data source this query on every sort, filter, search,
// or page change, along with an AbortSignal for the request it replaces.
// `aggregates` names the grand totals to compute over every matching row;
// it is sent on the first load and when filters or aggregations change, and
// goes out empty on a page or sort change so the totals aren't recomputed.
import type { ServerAggFn } from "@/components/pro-grid"
import type { ColumnType } from "@/components/pro-grid"
type FilterOperator =
// string
| "contains"
| "notContains"
| "startsWith"
| "endsWith"
// string + number + date + boolean
| "equals"
| "notEquals"
// number + date
| "gt"
| "gte"
| "lt"
| "lte"
| "inRange"
// membership — "is any of" for a scalar, "has any of" for an array cell
| "in"
| "notIn"
// array only
| "hasAll"
// date only — `value` is a day count relative to when the filter runs
| "inLast"
| "inNext"
// any type
| "blank"
| "notBlank"
type ConditionJoin = "AND" | "OR"
type FilterCondition = {
operator: FilterOperator
value: unknown
/** Upper bound — `inRange` only. */
valueTo?: unknown
}
/** One column's filter: up to two conditions combined with AND/OR. */
type ColumnFilter = {
id: string
/**
* The column's primitive. Carried on the filter rather than looked up, so a
* filter stays self-describing once it has left the grid — the serialized
* `?filters=` blob and a server-side evaluator both need to know how to
* compare the values, and neither can see the column definitions.
*/
type: ColumnType
conditions: FilterCondition[]
join: ConditionJoin
}
type SortSpec = { id: string; desc: boolean }
/**
* One grand total the grid wants computed over *every* row the filters match,
* not just the fetched page. `id` is a column id, like `sort[].id` — the
* data-adapter layer maps it to an API field.
*/
type AggregateSpec = { id: string; fn: ServerAggFn }
/** Everything the grid knows about what the host should fetch. */
type GridQuery = {
/** 0-based. */
page: number
pageSize: number
sort: SortSpec[]
filters: ColumnFilter[]
/** Toolbar quick-filter text ("" when empty). */
quickFilter: string
/** Active row grouping — only meaningful if your API can group. */
grouping: string[]
/**
* Grand totals to compute over the whole filtered result set. The grid always
* sets it (empty when no column has a server-capable aggregation selected);
* optional in the type so a hand-built query still compiles.
*
* A `dataSource` receives it only on requests that need fresh totals — first
* load, refresh, and whenever filters or the aggregation choices change. A
* page or sort change alone sends an empty list, because neither moves a
* grand total, and the grid keeps the totals it already has.
*/
aggregates?: AggregateSpec[]
}
const query: GridQuery = {
page: 0,
pageSize: 8,
sort: [],
filters: [],
quickFilter: "",
grouping: [],
aggregates: [
{ id: "units", fn: "sum" },
{ id: "revenue", fn: "sum" },
],
}
// The mock source answers after 420 ms with the page, the matching total, and
// the totals over all matching rows. A real source would return the same
// shape from `/api/orders?…`.
const response = {
rows: [
{
"id": "ORD-10482",
"customer": "Keystone Foods",
"channel": "Direct",
"region": "North America",
"owner": "Theo Martins",
"status": "Complete",
"priority": "Normal",
"units": 18,
"revenue": 1850,
"margin": 12,
"slaHours": 2,
"updatedAt": "2026-08-01T08:00:00.000Z"
},
{
"id": "ORD-10483",
"customer": "Atlas Manufacturing",
"channel": "Partner",
"region": "North America",
"owner": "Jon Bell",
"status": "Delayed",
"priority": "Critical",
"units": 55,
"revenue": 9769,
"margin": 25,
"slaHours": 7,
"updatedAt": "2026-08-02T09:00:00.000Z"
},
// …6 more rows
],
total: 240,
aggregates: {
units: 54540,
revenue: 11360920,
},
}Mock API · 420 ms latency
Waiting for the first query…Server order queue
Order
Customer
Region
Status
Units
Revenue
Total
0 rows
Rows per page
No rowsThings to try
- Change the sort and watch the request
- Filter a column
- Type in the quick filter
- Page forward while a request is in flight
The Code tab above is the component rendering this page; the Data tab is what reaches the grid. The props behind it are explained in Server-side data.