Example: Client table
Load a small dataset once (static JSON, parent query, or local fetch), then let the DataTable handle the rest in the browser.
"use client";
import { useEffect, useState } from "react";
import type { ColumnDef } from "@tanstack/react-table";
import {
DataTable,
DataTableColumnHeader,
} from "@/components/datatable";
type Country = {
code: string;
name: string;
region: "EU" | "NA" | "ASIA" | "OTHER";
};
const columns: ColumnDef<Country>[] = [
{
id: "name",
accessorKey: "name",
header: ({ column }) => (
<DataTableColumnHeader column={column} title="Name" />
),
enableSorting: true,
enableColumnFilter: true,
meta: {
variant: "text",
label: "Name",
placeholder: "Search name...",
},
},
{
id: "code",
accessorKey: "code",
header: ({ column }) => (
<DataTableColumnHeader column={column} title="Code" />
),
enableSorting: true,
enableColumnFilter: true,
meta: { variant: "text", label: "Code" },
},
{
id: "region",
accessorKey: "region",
header: ({ column }) => (
<DataTableColumnHeader column={column} title="Region" />
),
enableColumnFilter: true,
meta: {
variant: "select",
label: "Region",
options: [
{ label: "Europe", value: "EU" },
{ label: "North America", value: "NA" },
{ label: "Asia", value: "ASIA" },
{ label: "Other", value: "OTHER" },
],
},
},
];
export function CountriesClientTable() {
const [countries, setCountries] = useState<Country[]>([]);
useEffect(() => {
void fetch("/api/countries")
.then((r) => r.json())
.then(setCountries);
}, []);
return (
<DataTable<Country>
columns={columns}
source={{ type: "client", data: countries }}
enableToolbar
enablePagination
showTotalRows
initialState={{
sorting: [{ id: "name", desc: false }],
pagination: { pageIndex: 0, pageSize: 10 },
}}
getRowId={(r) => r.code}
/>
);
}
No backend list contract required. Page/sort/filter still sync to the URL by default so links remain shareable for small admin tools.