ListPage Pattern
Config-driven list pages with React Query, infinite scroll or pagination, search, filters and row actions
A list page is one CrudConfig plus one <ListPage config={config} />. The config declares
columns, form, data fetching (query) and mutations; ListPage renders the table (or the
infinite list), search, filters, row actions and the create/view/edit dialogs from it.
app/admin/users/
├── config.tsx # 'use client' — CrudConfig (columns, form, query, mutations)
└── page.tsx # <ListPage config={config} />
lib/api/
└── users-client.ts # REST client: the one hop from the browser to your APIconfig.tsx must start with 'use client'
query and mutations run through React Query hooks, which only exist on the client.
1. The API Client
The browser calls your API directly; React Query owns caching. The list call must resolve
PaginatedResponse<T>:
import type { PaginatedResponse, PaginationParams } from '@telamonjs/ui'
export const usersApi = {
async list(params: PaginationParams): Promise<PaginatedResponse<User>> {
const qs = new URLSearchParams({
page: String(params.page),
pageSize: String(params.pageSize),
...(params.search ? { search: params.search } : {}),
...(typeof params.sortBy === 'string' ? { sortBy: params.sortBy, sortOrder: params.sortOrder ?? 'asc' } : {}),
...params.filters, // toolbar/column/URL filters, keyed by filter key
})
const res = await fetch(`/api/users?${qs}`, { credentials: 'include' })
if (!res.ok) throw new Error('Failed to load users')
return res.json() // { data, total, page, pageSize, totalPages }
},
// create / update / delete / get return the raw entity (or nothing)
}Error messages and the server-side helpers are in
Data Layer (React Query). By default sortBy is the column id
(customer_name for accessorKey: 'customer.name'); list.sortParam: 'path' sends the data path
instead — see what sortBy carries.
2. config.tsx
'use client'
import { z } from 'zod'
import type { CrudColumnDef, CrudConfig, FormSection } from '@telamonjs/ui'
import { usersApi } from '@/lib/api/users-client'
export const validationSchema = z.object({
name: z.string().min(1, 'Name is required'),
email: z.string().email('Invalid email'),
role: z.enum(['USER', 'ADMIN']),
})
export type UserFormData = z.infer<typeof validationSchema>
const columns: CrudColumnDef<User>[] = [
{ accessorKey: 'name', header: 'Name' },
{ accessorKey: 'email', header: 'Email' },
{ accessorKey: 'role', header: 'Role' },
]
const formSections: FormSection[] = [
{
label: 'User',
fields: [
{ name: 'name', label: 'Name', type: 'text', required: true },
{ name: 'email', label: 'Email', type: 'email', required: true },
{
name: 'role',
label: 'Role',
type: 'relationship', // there is no 'select' field type
required: true,
loadField: async () => [
{ value: 'USER', label: 'User' },
{ value: 'ADMIN', label: 'Admin' },
],
},
],
},
]
export const config: CrudConfig<User, UserFormData> = {
module: { name: 'users', title: 'Users', description: 'Manage system users', route: '/admin/users' },
list: { title: 'Users', description: 'Registered users', columns, searchPlaceholder: 'Search users...' },
form: { sections: formSections, validation: validationSchema },
// queryFn receives { page, pageSize, search, sortBy, sortOrder, filters }
// and must resolve PaginatedResponse<User>
query: { queryKey: ['users'], queryFn: usersApi.list },
mutations: {
// mutationFn must resolve { success, data? } — adapt the raw API response here
create: {
mutationFn: async data => ({ success: true, data: await usersApi.create(data) }),
invalidates: [['users']],
},
update: {
mutationFn: async ({ id, data }) => ({ success: true, data: await usersApi.update(id, data) }),
invalidates: [['users'], id => ['users', id]],
},
delete: {
mutationFn: async ({ id }) => {
await usersApi.delete(id)
return { success: true }
},
invalidates: [['users']],
},
getForEdit: usersApi.get,
getForView: usersApi.get,
},
actionsConfig: { standard: { view: true, edit: true, delete: true } },
dialogs: {
view: { title: 'User', urlParam: 'view', renderContent: user => <UserDetail user={user} /> },
edit: { title: 'Edit user', urlParam: 'edit' },
create: { title: 'New user', urlParam: 'create', defaultValues: { role: 'USER' } },
},
}invalidates must include the list's query.queryKey, or the list will not refresh after a
mutation. Each mutation is optional: omit create for a read-only module and the create
button is not wired. The full mutation contract (toasts, onSuccess/onError, invalidation
rules) is in Data Layer (React Query).
3. page.tsx
import { ListPage } from '@telamonjs/ui'
import { config } from './config'
export default function UsersPage() {
return <ListPage config={config} />
}ListPage props
| Prop | Type | Purpose |
|---|---|---|
config | CrudConfig<T, TFormData> | Required. Everything about the module |
tableId | string | Key of the table state in the Zustand store. Default: config.module.route |
urlSync | boolean | Keeps page, page size, sort and search in the query params; a link carrying them opens the list there, and Back/Forward or a link to the same page update the list. With infinite scroll (the default) only sort and search: every load starts at page 1 |
urlFilters | Record<string, 'string' | 'number'> | Extra filters read from the URL (with urlSync) and passed to queryFn |
filterOptions / loadFilterOptions | ColumnFilterConfig / () => Promise<ColumnFilterConfig> | Column filter options, static or loaded on mount |
enableBulkActions / bulkActions | boolean / BulkAction<T>[] | Checkbox column and toolbar for selected rows |
headerActions | { label, icon?, onClick, variant?, loading? }[] | Extra toolbar buttons |
toolbarPrepend / toolbarContent | ReactNode | Custom toolbar content before search / after filters |
filtersPanel, activeFilters, onClearFilters, footerContent | Second toolbar level (see below) | |
cardComponent | ComponentType<{ data; onClick? }> | Custom card for the mobile view of the paginated table (the infinite list has no mobile cards) |
embedded | boolean | Render inside a container that owns the toolbar (e.g. a tab) |
header | ReactNode | Bars, alerts or status panels above the toolbar, inside the list (see Content above the list) |
dialogUrlSync | boolean | Set false for a ListPage inside another ListPage's dialog (see Dialogs) |
onRefreshAction | () => Promise<void | { success }> | Runs after every list refresh (see Refreshing) |
disableAutoRefresh | boolean | Default true. Set false to refetch when the window regains focus |
errorBoundary, errorFallback, className | Error boundary (on by default) and styling |
Infinite Scroll vs Pagination
ListPage renders a virtualized infinite list by default. It stops fetching using page,
totalPages and total from the PaginatedResponse — a queryFn resolving a bare array
misbehaves silently. Set list.infiniteScroll: false for the classic paginated table.
interface PaginationParams {
page: number
pageSize: number
search?: string
sortBy?: string | SortField[]
sortOrder?: 'asc' | 'desc'
filters?: Record<string, any>
}
interface PaginatedResponse<T> {
data: T[]
total: number
page: number
pageSize: number
totalPages: number
}queryFn receives ListQueryParams: the same fields with sortBy already a single column
(a string). createPaginatedResponse(data, total, page, pageSize) builds the response when you
page a local array.
Keep the paginated table when the backend cannot return page/totalPages (cursor
pagination, for example), when users need "jump to page N", or for short lists.
The infinite list requests list.defaultPageSize rows per page (50 when unset). In a standalone
page it fills its parent and scrolls inside itself, not the window, so the parent (normally the
AdminShell main area) must give it a height.
Dialogs
With dialogs.view, dialogs.edit and dialogs.create set, every CRUD step happens in dialogs
on top of the list: view and edit rows open their dialog, the toolbar's create button opens
the create dialog, and the edit form submits through mutations.update. Dialog content, rich
headers and sizes are covered in Dialogs.
Deep links (urlParam)
Give a dialog a query-param name and it becomes linkable:
dialogs: {
view: { title: 'User', urlParam: 'view', renderContent }, // ?view=<id>
edit: { title: 'Edit user', urlParam: 'edit' }, // ?edit=<id>
create: { title: 'New user', urlParam: 'create' }, // ?create=1 (no id)
},ListPage keeps the dialog and the URL in sync both ways:
| Event | Effect |
|---|---|
| Page load, client navigation, browser Back/Forward | The dialog opens or closes to match the URL |
| The user opens a dialog | router.push, so the browser's Back button closes it |
| The user closes it (X, Esc) | router.replace, with no extra history entry |
- Other params (
?tab,?page,?sort, filters) are kept, so/admin/registry?tab=assets&view=42works. - If several dialog params are present, only one dialog opens:
editwins overview, which wins overcreate. - Several lists mounted on one route (keep-alive tabs) can share the same param name: only the visible list opens its dialog from the URL.
- A ListPage rendered inside another ListPage's dialog (for example, tabs of a record opened
with the parent's
?view=<id>) must getdialogUrlSync={false}. Otherwise it reads the parent's id as its own and opens a dialog for a record that does not exist.
urlParam is optional; a dialog without it is not driven by the URL.
Row Actions
actionsConfig.standard turns on view/edit/delete (true or an ActionConfig); view and
edit open the dialogs, delete asks for confirmation and runs mutations.delete. Pass an
ActionConfig to change the icon, tooltip or confirmation text:
actionsConfig: {
standard: {
view: true,
edit: true,
delete: {
tooltip: 'Deactivate user',
confirmDialog: {
title: row => `Deactivate ${row.name}?`,
description: 'This cannot be undone.',
confirmText: 'Deactivate',
variant: 'destructive',
},
},
},
custom: [
{
id: 'publish',
label: 'Publish',
icon: Upload,
handler: row => processesApi.publish(row.id),
confirmDialog: {
title: row => `Publish process ${row.number}?`,
confirmText: 'Publish',
},
visible: row => row.status === 'DRAFT',
},
],
},actionsConfig.custom adds actions beyond CRUD. After a custom handler succeeds, the list
refetches by itself; resolve { success: false } to skip that. Set actionsConfig: false to
hide the actions column.
ActionConfig also takes href, onClick, enabled, tooltip, variant, permission,
successMessage and errorMessage.
confirmDialog.inputs asks for values before confirming (a reason, a note); they reach the
handler as (row, { inputs }). The dialog stays open while the action runs and after a
failure — see ConfirmActionDialog, which is also
available for your own buttons.
permission is checked against actionsConfig.userPermissions by exact name. Set
actionsConfig.can (or config.permissions.can, or once for the app a PermissionsProvider,
see Permissions) to decide it with your own
checker instead, so a bypass role with no listed permissions still sees the actions.
Bulk Actions
enableBulkActions adds a checkbox column and a toolbar for the selected rows, in both the
infinite list and the paginated table:
const bulkActions: BulkAction<Order>[] = [
{
id: 'approve',
label: 'Approve selected',
confirmDialog: {
title: rows => `Approve ${rows.length} orders?`,
description: 'Each order is approved individually.',
},
handler: async rows => {
await ordersApi.approveMany(rows.map(r => r.id))
return { success: true, message: `${rows.length} approved` }
},
},
]
<ListPage config={config} enableBulkActions bulkActions={bulkActions} />- In the infinite list, the header checkbox selects every row already loaded. Rows not yet fetched are never part of the selection, and the status bar says "N selected of M loaded".
- Selection is kept by row
id; it is cleared after a successful action, and the list refetches. - The ids
deleteandexportrender as direct buttons; other actions go into a "more" menu.
Search and Filters
Global Search
The search box value reaches queryFn as params.search; filter on the API side.
list.searchPlaceholder sets the placeholder, and list.toolbar.showSearch: false hides it.
Toolbar Filters
Declare filters in list.toolbar.filters. Each selection reaches queryFn as
params.filters[key]; the values 'all' and '' mean "no filter" and are dropped.
list: {
title: 'Users',
description: 'Registered users',
columns,
toolbar: {
filters: [
{
key: 'status',
label: 'Status',
options: [
{ value: 'all', label: 'All' },
{ value: 'ACTIVE', label: 'Active', dot: 'bg-green-500' },
{ value: 'INACTIVE', label: 'Inactive', dot: 'bg-gray-400' },
],
displayMode: 'buttons', // or 'select' for a compact dropdown
},
],
},
},By default the first option is the "all" choice: in buttons mode it is not rendered, and
defaultValue only applies when it is not the first option. Set allValue to name the "no
filter" value explicitly instead — the first option becomes an ordinary option, defaultValue
always applies, and 'all'/'todos' are ordinary values:
{
key: 'status',
label: 'Status',
allValue: 'ANY',
defaultValue: 'ACTIVE', // applied on load even though it is the first option
options: [
{ value: 'ACTIVE', label: 'Active' },
{ value: 'INACTIVE', label: 'Inactive' },
{ value: 'ANY', label: 'All' },
],
}Active / inactive preset
For a boolean "active" column, activeFilter(key = 'active', overrides?) returns that filter
ready-made: All / Active / Inactive, labelled by the library messages (every locale), with
allValue: 'all'. "Active" sends ?<key>=true, "Inactive" ?<key>=false and "All" sends
nothing, which is what a 'boolean' filter of
@telamonjs/data parses. The overrides are label, defaultValue,
displayMode and className:
import { activeFilter } from '@telamonjs/ui'
toolbar: {
filters: [activeFilter('ativo', { defaultValue: 'true' })], // opens on the active rows
},Filters in the URL
With urlSync, a toolbar filter whose key is also in urlFilters round-trips with the URL:
<ListPage config={config} urlSync urlFilters={{ status: 'string' }} />- Opening
?status=ACTIVEfilters the data and selects "Active" in the toolbar. - Changing the filter writes
?status=; going back to "All" removes the param. - Toolbar filters not listed in
urlFiltersstay in memory only. Keys inurlFiltersthat are not toolbar filters are read from the URL (on mount, and again on Back/Forward or a link to the same page) and passed toqueryFn.
For a "Filters" panel with selectors, date ranges and text fields that stays in sync with the
URL — reload, Back and shared links keep it — use useUrlFilters.
It returns filtersPanel, activeFilters and onClearFilters for ListPage, plus the active
values:
const { values, filtersPanel, activeFilters, onClearFilters } = useUrlFilters(FILTERS)
// values reach the data through config.query, memoized on them
const config = useMemo(
() => ({
...ordersConfig,
query: {
...ordersConfig.query,
queryKey: [...ordersConfig.query.queryKey, values],
queryFn: (params: ListQueryParams) =>
ordersConfig.query.queryFn({ ...params, filters: { ...params.filters, ...values } }),
},
}),
[values]
)
<ListPage config={config} filtersPanel={filtersPanel} activeFilters={activeFilters} onClearFilters={onClearFilters} />- Do not put the hook's params in
urlFilters.urlFiltersis read once on mount and its sync writes those keys back with the mount values, undoing every change made in the panel. valuesis a stable object (same identity until a filter changes), so it can key the config'suseMemoand the query.
Toolbar levels
A crowded toolbar can move secondary controls into a second level. All of these are opt-in:
| Option | Where | Effect |
|---|---|---|
filtersPanel | ListPage prop | Content of a "Filters" popover (selects of client, period...) |
activeFilters | ListPage prop | ActiveFilterChip[] (key, label, onRemove) shown as removable chips under the toolbar |
onClearFilters | ListPage prop | "Clear filters" next to the chips |
more: true | filter option | The option leaves the toolbar buttons and appears in the "Filters" panel, as a chip when active |
toolbar.actionsMenu | list.toolbar | Export and Refresh in one "⋯" menu instead of two buttons |
footerContent adds content to the list status bar, after "N of M" (infinite scroll), such as the
totals of the current filter.
Content above the list
A bar, alert or status panel that sits above an embedded list (a tab, a panel) goes in header,
not next to the ListPage:
<ListPage
config={config}
embedded
header={<Alert>Results are preliminary until the deadline.</Alert>}
/>header renders inside the list's root, before the toolbar. In the flex-column layouts (embedded
or infinite scroll) it keeps its own height and the table fills the rest of the panel, so the
footer stays at the bottom without extra scroll. No wrapper is needed: a sibling above the
ListPage either leaves the list without a height (footer mid-screen) or adds to its 100%
height (footer below the viewport). In the paginated standalone layout it is the page's first
block.
Your own button with the list's query
toolbarContent also takes a function. It receives the list's current query
(ListQueryState) and re-renders when it changes, so an export or PDF button fetches exactly
what the list shows:
<ListPage
config={ordersConfig}
toolbarContent={({ params }) => (
<Button
variant='outline'
size='sm'
onClick={() => ordersApi.downloadPdf({ ...params, page: 1, pageSize: 10_000 })}
>
PDF
</Button>
)}
/>| Field | Content |
|---|---|
search | the search box value, as typed |
filters | every active filter: toolbar filters (resets dropped), column filters, urlFilters |
sorting | the current sort (SortField[]) |
params | the ListQueryParams the list passes to query.queryFn (debounced search, current page, sortBy as the first sort column) |
toolbarContent renders in the list toolbar: infinite scroll (the default) and embedded.
Exporting every row, or exporting on the server
list.enableExport puts an Excel/CSV/PDF menu in the toolbar. Its "All" exports the rows already
loaded in the browser. With infinite scroll (the default) that is only the pages scrolled so far,
so a 2 000-row list with defaultPageSize: 100 exports 100 rows. Two opt-ins change that:
list: {
enableExport: true,
// 1. Fetch every matching row through query.queryFn before generating the file
exportAll: true, // or { pageSize: 200, maxRows: 5_000 }
},list: {
// 2. Hand the export to your backend: the menu lists the formats and calls you
exportFormats: ['excel', 'csv'],
onExport: async ({ params }, format) => {
await ordersApi.export({ ...params, format }) // e.g. downloads a file or queues a job
},
},exportAll | onExport | |
|---|---|---|
| Who builds the file | the browser, with the list columns | your backend |
| Query | current search, filters and sort, page by page through query.queryFn | ListQueryState, the same object toolbarContent gets |
| Size | up to maxRows (10 000); past it the file holds the first rows and a warning says so | whatever your backend handles |
| UX | progress toast with Cancel; "Current page" still exports the loaded rows | formats only; the trigger shows a spinner until your promise settles |
| Cost | one request per page, sequential, so the backend sees the same load as scrolling | one request |
exportAll requests use exportAll.pageSize, else defaultPageSize (50 when unset): a size
your backend already accepts. Choose onExport when exports grow past a few thousand rows,
need columns the table does not show, or must be audited on the server. onExport shows the
menu even without enableExport; throw from it to show the export error toast. Announcing
success (or a queued job) is up to you. Both options apply to the paginated list
(infiniteScroll: false) as well.
Columns only in the export
meta.exportOnly keeps a column out of the table and in the CSV/Excel/PDF export, so a table that
merges fields into one cell does not lose data in the spreadsheet:
columns: [
{ accessorKey: 'client', header: 'Client', cell: ({ row }) => <ClientCell client={row.original} /> },
{ accessorKey: 'taxId', header: 'Tax ID', meta: { exportOnly: true } },
]Lists Scoped to a Parent
A child list inside a parent record (a customer's contacts tab, for example) reuses the child
module's config through withScope:
import { ListPage, withScope } from '@telamonjs/ui'
const customerContacts = withScope(contactsConfig, {
filters: { customerId }, // merged into params.filters and the queryKey
locked: { customerId }, // hidden from form, columns and filters; injected on create
invalidates: [['customers', customerId]],
})
<ListPage config={customerContacts} embedded />defaults adds editable create defaults. withScope returns a new config and never mutates the
original. It replaces an inline CRUD field when the child list is
large or needs search, filters and paging.
Refreshing
React Query is the cache. Mutations refresh the list through invalidates; the toolbar's
refresh button and successful row or bulk actions refetch the query. Two optional hooks:
AppProvidersconfig.revalidateActionruns first, with the current pathname, to clear the app's Server Component cache. UserevalidatePathActionfrom@telamonjs/ui/server.onRefreshAction(ListPageprop) runs after the refetch, for example to invalidate other modules that show the same data:
'use client'
import { useQueryClient } from '@tanstack/react-query'
import { ListPage } from '@telamonjs/ui'
export default function CustomersPage() {
const queryClient = useQueryClient()
return (
<ListPage
config={customersConfig}
onRefreshAction={async () => {
await queryClient.invalidateQueries({ queryKey: ['orders'] })
}}
/>
)
}Checklist
-
config.tsxstarts with'use client' -
query.queryFnresolvesPaginatedResponse<T>(data,total,page,pageSize,totalPages) - Every
mutationFnresolves{ success, data? } - Every mutation's
invalidatesincludes the list'squeryKey - Columns are typed
CrudColumnDef<T>[], and the form-data type is inferred from the Zod schema - Dropdowns use
type: 'relationship'withloadField -
page.tsxrenders<ListPage config={config} />
Troubleshooting
The list never stops loading, or only shows the first page
queryFn returns a bare array or a response without page/totalPages. Return
PaginatedResponse<T>, or set list.infiniteScroll: false.
The record was saved, but the dialog stays open
The mutationFn resolves the raw entity instead of { success, data? }. Adapt inside the
mutationFn: async data => ({ success: true, data: await api.create(data) }).
The list does not update after create/edit/delete
The mutation's invalidates does not match query.queryKey.
"No QueryClient set"
config.tsx is missing 'use client', the app has no QueryClientProvider, or two copies of
@tanstack/react-query are installed. See Provider Setup.
Search or filters do nothing
The API ignores params.search / params.filters. Log the params your queryFn receives.
A list inside a dialog opens a dialog for the wrong record
It reads the parent's ?view=<id>. Pass dialogUrlSync={false} to the inner ListPage.
Related Patterns
- CrudConfig - The config object in detail
- Data Layer (React Query) - API client, mutations and invalidation
- Admin Module Structure - What goes in
config.tsx - Form Pattern - Forms used by the dialogs
- Dialogs - View, edit and create dialogs
- Field Types - All field types