Skip to content
Design System
GitHub

The query a server-paged list sends (page, limit, sortBy, order, search) and the page it gets back (items, total), read from and written to URLSearchParams.

Install
npx shadcn add @syncrobotic/list-query

Overview

When to use

  • Every list the server pages: devices, members, audit events, webhook deliveries.
  • Reading a list's query in a server component, so the first HTML shows the right page.
  • Building the request: serializeListQuery(query, { complete: true }).

Use something else

  • A short list the page holds whole (under a few hundred rows): filter it in the browser with Filters.

Usage rules

  • One grammar for every server-paged list: page (from 1), limit, sortBy, order and search, the same names in the URL, the request and the server's page options.
  • Counts come from ListPage.total: the items are one page, and the server may cap them. Never count items.length for a tab, a heading or a metric.
  • Parse on the server too: parseListQuery(searchParams) in a server component reads the same query the browser will.
  • Bound what a hand-edited URL may ask for: sortable lists the columns, maxLimit the largest page.

API

What the file exports. The source is in the Source sheet above.

defaultListQuery
parseListQuery(input: ListQueryInput, options?: ListQueryOptions): ListQuery
Reads a query from the URL.
serializeListQuery(query: Partial<ListQuery>, options?: ListQueryOptions & { base?: ListQueryInput; complete?: boolean }): URLSearchParams
Writes a query into URLSearchParams.
pageCount(total: number, limit: number)
How many pages `total` rows make at `limit` a page: at least 1, so an empty list still has its first page.
pageRange(query: Pick<ListQuery, "page" | "limit">, total: number)
The rows a page shows, 1-based, for "21–40 of 135".
clampPage<Q extends Pick<ListQuery, "page" | "limit">>(query: Q, total: number): Q
The query on its last page when it asks for one past the end (rows were deleted, or a stale link).

Types

SortOrderListQueryListPageListQueryKeysListQueryOptionsListQueryInput

Changelog

  • 0.64.02026-12-01Formatted with Prettier (class order sorted); the code is unchanged.
  • 0.55.02026-11-27First release: ListQuery, ListPage<T>, parseListQuery (malformed values fall back to the defaults; sortable and maxLimit bound a hand-edited URL), serializeListQuery (keeps other keys, leaves defaults out), pageCount, pageRange and clampPage.

How to upgrade