"use client" import { type Table } from "@tanstack/react-table" import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, } from "@kandev/ui/pagination" import { Button } from "@kandev/ui/button" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@kandev/ui/select" import { IconChevronLeft, IconChevronRight, IconChevronsLeft, IconChevronsRight, } from "@tabler/icons-react" interface DataTablePaginationProps { table: Table } export function DataTablePagination({ table, }: DataTablePaginationProps) { const currentPage = table.getState().pagination.pageIndex + 1 const pageCount = table.getPageCount() // Generate page numbers to display const getPageNumbers = () => { const pages: (number | 'ellipsis')[] = [] const showPages = 5 // Max pages to show if (pageCount <= showPages) { // Show all pages for (let i = 1; i <= pageCount; i++) { pages.push(i) } } else { // Always show first page pages.push(1) if (currentPage > 3) { pages.push('ellipsis') } // Pages around current const start = Math.max(2, currentPage - 1) const end = Math.min(pageCount - 1, currentPage + 1) for (let i = start; i <= end; i++) { pages.push(i) } if (currentPage < pageCount - 2) { pages.push('ellipsis') } // Always show last page if (pageCount > 1) { pages.push(pageCount) } } return pages } return (
{table.getFilteredRowModel().rows.length > 0 && ( <> Showing {table.getState().pagination.pageIndex * table.getState().pagination.pageSize + 1} to{" "} {Math.min( (table.getState().pagination.pageIndex + 1) * table.getState().pagination.pageSize, table.getRowCount() )}{" "} of {table.getRowCount()} results )}

Rows per page

{getPageNumbers().map((page, idx) => page === 'ellipsis' ? ( ) : ( ) )}
) }