TanStack Table core sorting, filtering and pagination: working versions (tested 2026-10-15)
Use @tanstack/table-core headlessly to sort, filter and paginate row models without React, asserting filtered and page rows in plain Node tests.
passed2 passed · 0 failed2026-10-15 16:05 UTC- Status
- passed
- Last passed
- 2026-10-15 16:05 UTC
- Tests
- 2 / 2
- Language
- TypeScript
- Runtime
- node v22.23.3
pinned versions3
@tanstack/table-core@8.21.3@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false npm test
test environment
node v22.23.3 linux 6.17.0-1022-azure x64 runner: github-actions 38764699834
The code
Exactly the files that passed. Your agent can pull them with get_recipe("tanstack-table-core-sorting") (install), or see them on GitHub.
package.json
{
"name": "tanstack-table-core-sorting",
"private": true,
"type": "module",
"scripts": {
"test": "node --import tsx --test test/*.test.ts"
},
"dependencies": {
"@tanstack/table-core": "8.21.3"
},
"devDependencies": {
"@types/node": "26.6.5",
"tsx": "4.23.15"
}
}
src/people.ts
import {
createTable,
getCoreRowModel,
getFilteredRowModel,
getPaginationRowModel,
getSortedRowModel,
type ColumnDef,
type SortingState,
type ColumnFiltersState,
type PaginationState,
} from "@tanstack/table-core";
export type Person = { id: number; name: string; role: string; score: number };
export const columns: ColumnDef<Person>[] = [
{ accessorKey: "name", header: "Name" },
{ accessorKey: "role", header: "Role" },
{ accessorKey: "score", header: "Score" },
];
export function buildTable(opts: {
data: Person[];
sorting?: SortingState;
filters?: ColumnFiltersState;
pagination?: PaginationState;
}) {
return createTable({
data: opts.data,
columns,
state: {
sorting: opts.sorting ?? [],
columnFilters: opts.filters ?? [],
pagination: opts.pagination ?? { pageIndex: 0, pageSize: 2 },
},
onStateChange: () => {},
renderFallbackValue: null,
getCoreRowModel: getCoreRowModel(),
getSortedRowModel: getSortedRowModel(),
getFilteredRowModel: getFilteredRowModel(),
getPaginationRowModel: getPaginationRowModel(),
});
}
export function pageNames(table: ReturnType<typeof buildTable>) {
return table.getRowModel().rows.map((r) => r.original.name);
}
test/people.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { buildTable, pageNames, type Person } from "../src/people.ts";
const data: Person[] = [
{ id: 1, name: "Ada", role: "admin", score: 90 },
{ id: 2, name: "Bob", role: "member", score: 70 },
{ id: 3, name: "Cy", role: "admin", score: 95 },
{ id: 4, name: "Dee", role: "guest", score: 40 },
];
test("sorts by score descending", () => {
const t = buildTable({ data, sorting: [{ id: "score", desc: true }], pagination: { pageIndex: 0, pageSize: 10 } });
assert.deepEqual(pageNames(t), ["Cy", "Ada", "Bob", "Dee"]);
});
test("filters by role then paginates", () => {
const t = buildTable({
data,
filters: [{ id: "role", value: "admin" }],
pagination: { pageIndex: 0, pageSize: 1 },
});
assert.equal(t.getFilteredRowModel().rows.length, 2);
assert.deepEqual(pageNames(t), ["Ada"]);
const page2 = buildTable({
data,
filters: [{ id: "role", value: "admin" }],
pagination: { pageIndex: 1, pageSize: 1 },
});
assert.deepEqual(pageNames(page2), ["Cy"]);
});
Connect to ProvenPin
Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.
terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp
~/.cursor/mcp.json
{ "mcpServers": { "provenpin": { "url": "https://mcp.provenpin.com/mcp" } } }.vscode/mcp.json
{ "servers": { "provenpin": { "type": "http", "url": "https://mcp.provenpin.com/mcp" } } }~/.codeium/windsurf/mcp_config.json
{ "mcpServers": { "provenpin": { "serverUrl": "https://mcp.provenpin.com/mcp" } } }MCP settings
{ "mcpServers": { "provenpin": { "type": "streamableHttp", "url": "https://mcp.provenpin.com/mcp" } } }Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.