#122
Controlled mode
A DataTable driven from outside: filter, sort and pagination state live in the page, which slices 12 users into pages of 5.
Hand this to your AI. It names the exact library parts, timings and accessibility promises of this demo.
Build the "Controlled mode" pattern (@codeatlasdev/ui demo #122, display/data-table) in my app.
Call get_demo({ ids: ["#122"] }) first and keep its structure. It needs @codeatlasdev/[email protected] + @tanstack/svelte-table.
Use: Server-side or externally managed tables where the page owns search, sort and paging state.
Keep these library parts, with the props and tokens the demo uses:
- DataTable, createCaColumnHelper from "@codeatlasdev/ui/table"
Behaviour to keep:
- `let globalFilter = $state('')`, `let pagination = $state<PaginationState>({ pageIndex: 0, pageSize: 5 })` and `let sorting = $state<SortingState>([])`
- `const allData: User[]` has 12 rows with `id`, `name`, `email`, `role` and `status`
- `<DataTable` receives `data={pageData}`, `total={filtered.length}`, `{globalFilter}`, `{onGlobalFilterChange}`, `{pagination}`, `{onPaginationChange}`, `{sorting}` and `{onSortingChange}`
- `searchPlaceholder="Search by name, email, role…"` sets the search input hint
- `createCaColumnHelper<User>()` defines 5 columns with `col.accessor`
- `onGlobalFilterChange` resets `pageIndex: 0`
Reduced motion: the demo handles it; keep that branch.
Keyboard: operable; keep the focus order and key handling.
Change only the copy and the data. Use the theme tokens (--ca-*), never raw colours. Library parts
- DataTable
@codeatlasdev/ui/table
How it is built
- `let globalFilter = $state('')`, `let pagination = $state<PaginationState>({ pageIndex: 0, pageSize: 5 })` and `let sorting = $state<SortingState>([])`
- `const allData: User[]` has 12 rows with `id`, `name`, `email`, `role` and `status`
- `<DataTable` receives `data={pageData}`, `total={filtered.length}`, `{globalFilter}`, `{onGlobalFilterChange}`, `{pagination}`, `{onPaginationChange}`, `{sorting}` and `{onSortingChange}`
- `searchPlaceholder="Search by name, email, role…"` sets the search input hint
- `createCaColumnHelper<User>()` defines 5 columns with `col.accessor`
- `onGlobalFilterChange` resets `pageIndex: 0`
Related
Loading source.