noora
Sign in

Pagination group

Moves between the pages of a list or table with a known number of pages.

Default

Pages before and after the current one, with the first and last page always in reach.

<.pagination_group
  current_page={1}
  number_of_pages={12}
  page_patch={fn page -> "?test-runs-page=" <> Integer.to_string(page) end}
/>

Middle page

Away from the edges, ellipses replace the pages on both sides.

<.pagination_group
  current_page={6}
  number_of_pages={12}
  page_patch={fn page -> "?test-runs-page=" <> Integer.to_string(page) end}
/>

Last page

The next button is disabled on the last page.

<.pagination_group
  current_page={12}
  number_of_pages={12}
  page_patch={fn page -> "?test-runs-page=" <> Integer.to_string(page) end}
/>

Few pages

When the current page and its neighbors reach both ends, no ellipsis is needed.

<.pagination_group
  current_page={3}
  number_of_pages={5}
  page_patch={fn page -> "?test-runs-page=" <> Integer.to_string(page) end}
/>

Guidelines

  • Use a pagination group when you know the total number of pages. It does not fit cursor-based pagination, where the total is unknown.
  • Pass page_patch a function that takes a page number and returns the path to that page, usually the current query with the page parameter replaced.
  • Name the page parameter after the list it paginates, such as test-runs-page , so several paginated lists can share a page.
  • Render the group only when there is more than one page.
  • The previous and next buttons are disabled on the first and last page. Long ranges collapse into ellipses around the current page.

API reference

<.pagination_group>

Attribute Type Default Description
current_page Required
integer
–
The current page number.
number_of_pages Required
integer
–
The number of pages to display.
page_patch Required
fun
–
Get a patch for an individual page where the input is the index.

Also accepts global attributes.