PrevNextButtons

Renders navigation buttons that link to the previous and next records of the current resource, plus the index/total.

Installation

pnpm dlx shadcn@latest add @shadmin/prev-next-buttons

Usage

Place it inside a <Show> or <Edit> view (where a RecordContext is provided):

import { Edit, PrevNextButtons } from "@/components/admin";
 
const PostEdit = () => <Edit actions={<PrevNextButtons />}>...</Edit>;

By default the buttons link to the same kind of view as the current one (edit if inside an <Edit>, show if inside a <Show>). Use the linkType prop to override.

The component uses usePrevNextController from ra-core, which re-fetches a paginated list of records using the same filters/sort the user last used in the list view. Use the filter, sort, limit, and storeKey props to customize this query.

Props

PropRequiredTypeDefaultDescription
classNameOptionalstring-Additional classes on the wrapping <nav>
filterOptionalFilterPayload-Filters for the query that finds neighbouring records
filterDefaultValuesOptionalFilterPayload-Default filters merged with stored ones
limitOptionalnumber1000Max number of records fetched
linkTypeOptional"edit" | "show"inferredWhether the links target the edit or show view
queryOptionsOptionalUseQueryOptions-Options forwarded to the underlying TanStack Query call
refOptionalRef<HTMLElement>-Forwarded to the underlying <Button>
resourceOptionalstringFrom contextResource name
sortOptionalSortPayload-Sort order
storeKeyOptionalstring | false-Key used to find the saved list params (false disables)

ref

Forwards a ref to the underlying <Button> element.

import { useRef } from "react";
import { PrevNextButtons } from "@/components/admin";
 
const PostEdit = () => {
  const ref = useRef<HTMLElement>(null);
  return <Edit actions={<PrevNextButtons ref={ref} />}>...</Edit>;
};

linkType

Use linkType="show" from an <Edit> view to make the buttons link to the show view instead:

<PrevNextButtons linkType="show" />

filter and sort

When you want the prev/next navigation to follow a specific filter and sort independent from the list view, pass them explicitly:

<PrevNextButtons
  filter={{ status: "published" }}
  sort={{ field: "published_at", order: "DESC" }}
/>