shadcn.io is not affiliated with official shadcn/ui
Data Table examples · Advanced
Numeric Pagination Data Table for React
A table of invoices with numbered page buttons between Previous and Next.
Twenty-five invoices, five per page, with a button for each page between Previous and Next. The current page is a solid button and the rest are outlined; with more than seven pages the row keeps the first, the last and the neighbors of the current page, with an ellipsis for the gaps. Use it when people jump between pages rather than step through them.
Preview
Installation
FAQ
When does the ellipsis show?
getPageItems returns every page when there are seven or fewer, so these five pages all show. With more, it keeps the first and last pages and the ones around the current page, and puts an ellipsis where pages are skipped.
What happens when I click a page number?
The button calls table.setPageIndex(page). The current page uses variant="default" and aria-current="page"; the others use variant="outline". The ellipsis is text hidden from screen readers, not a button.
How many rows are on a page?
Five: initialState.pagination sets pageSize to 5, with rowPaginationFeature and createPaginatedRowModel(). Call table.setPageSize to change it; this demo has no page-size control.
Are Previous and Next still there?
Yes. They call table.previousPage() and table.nextPage() and are disabled at either end from getCanPreviousPage() and getCanNextPage().
Related
- Paginated Data TableA table of transactions, five per page
- Basic Data Table with CheckboxesA table of products with a checkbox on
- Expandable Sub-Rows Data TableA table of projects where each row
- Data Table with FiltersA table of users with two inputs that
- Data Table with ActionsA table of payments with a menu of
- Pagination Button GroupPagination in a button group with