Using the
PaginationElement and running into problems, first off what is
numberOfNeighbors? And how does one handle the left and right chevron when all that is provided to the
onChangefunction is the page number. and the page number is null
doesn anyone have any experience customizing a page in the admin tool with the Pagination component,
Please…
Hey
@923397761045512202
Are you referring to the pagination component at the bottom of the list view?
The one exported from
uiYes
The numberOfNeighbors represents how many numbers to show I believe
So it looks like
< 1 __2__ 3 >with numberofNeighbours = 1
If I'm not mistaken here
The challenge when using the component is jumping to start or end of the content
As in on the page? Navigating to the top after a page change?
The event handler doesn’t provide enough information
You mean when clicking the chevrons, right?
Yes
Are you opposed to using the
handlePageChangefunction from the
useListQueryhook? It's kind of already done for you
All you need is the inital request to get the docs, the format of that request already has all the pagination controls you need aside from the hook above
I am writing an image gallery using list view
Try the
useListQueryhook, you get
dataso no need for additional request actually, and that aforementioned hook
Is that clearly documented somewhere?
I was trying to wrap the other piece of content and just needed to handle the paging issue 😞
so i have absolutely no idea how that hook solves my problem?
'use client'
import { Pagination } from '@payloadcms/ui/elements/Pagination'
import { useRouter, usePathname } from 'next/navigation'
import { useListQuery } from '@payloadcms/ui'
const ClientPagination = ({
page,
limit,
totalPages,
hasNextPage,
hasPrevPage,
urlParams,
}: {
page: number
limit: number
totalPages: number
hasNextPage: boolean
hasPrevPage: boolean
urlParams: URLSearchParams
}) => {
const router = useRouter()
const pathname = usePathname()
const { data, handlePageChange: pageChange } = useListQuery()
debugger;
/**
* when the left or right chevron is clicked, the function is called and the newPage === null
*
* @param newPage
*/
const handlePageChange = (newPage: number) => {
debugger
// Get the current path
const path = pathname
// Get the current search params
const searchParams = new URLSearchParams(window.location.search)
// Update the search params
searchParams.set('page', newPage?.toString() || '1')
// Push the new search params
router.push(`${path}?${searchParams.toString()}`)
}
return (
<Pagination
page={page}
limit={limit}
totalPages={totalPages}
numberOfNeighbors={1}
hasNextPage={hasNextPage}
hasPrevPage={hasPrevPage}
onChange={handlePageChange}
/>
)
}
export default ClientPaginationWell it looks like you're not even using it, just pass it directly to onChange
It handles all the default behavior for the list view as is
You've renamed it to pageChange, but aren't using it anywhere
const { data, handlePageChange } = useListQuery()
return (
<Pagination
page={page}
limit={limit}
totalPages={totalPages}
numberOfNeighbors={1}
hasNextPage={hasNextPage}
hasPrevPage={hasPrevPage}
onChange={handlePageChange}
/>
)Have a look here:
https://github.com/payloadcms/payload/blob/main/packages/ui/src/views/List/index.tsx#L109thanks! i got it resolved
Oh sweet
Glad you figured it out here!
Star
Discord
online
Get dedicated engineering support directly from the Payload team.