Redpanda UIRedpanda UI
Hooks

useDataTableSearchParams

Sync DataTable pagination, sorting, and filters to and from TanStack Router search params.

Installation

useDataTableSearchParams keeps a <DataTable>'s pagination, sorting, and column-filter state in the URL via TanStack Router search params — so table views are shareable, bookmarkable, and survive refreshes. It reads state from the current search params and writes updates back with navigate({ search, replace: true }). Each concern can be toggled independently, and a paramPrefix lets multiple tables coexist on one page.

Usage

import { useDataTableSearchParams } from "@/hooks/use-data-table-search-params";
import { DataTable } from "@/components/redpanda-ui/data-table";

function UrlSyncedTable() {
  const { pagination, onPaginationChange, sorting, onSortingChange } =
    useDataTableSearchParams({
      syncPagination: true,
      syncSorting: true,
    });

  return (
    <DataTable
      columns={columns}
      data={data}
      pagination={pagination}
      onPaginationChange={onPaginationChange}
      sorting={sorting}
      onSortingChange={onSortingChange}
    />
  );
}

API

useDataTableSearchParams(options?)

OptionTypeDefaultDescription
syncPaginationbooleantrueSync pagination to/from the URL.
syncSortingbooleantrueSync sorting to/from the URL.
syncFiltersbooleanfalseSync column filters to/from the URL.
paramPrefixstringPrefix for param keys (for multiple tables).
defaultPaginationPaginationState{ pageIndex: 0, pageSize: 10 }Fallback when the URL has no pagination params.
defaultSortingSortingState[]Fallback when the URL has no sorting params.

Returns { pagination, onPaginationChange, sorting, onSortingChange, filters, onFiltersChange } — state values and TanStack Table–compatible onChange handlers.

For cursor/token APIs that can't express offsets in the URL, use useTokenPagination.

Built by malinskibeniamin. The source code is available on GitHub.

On this page