"use client" /** * DataTablePaginated — DataTable with a bottom pagination bar * * Adds: * • "No. of Row" page-size selector * • First / Previous / Next / Last page buttons * • "{from}–{to} of {total}" status span (role="status" aria-live="polite") * • Keyboard: Left/Right arrow keys on the pagination bar change page * * Everything else (columns, pinning, resize, DnD, sort, filters, group, * selection) is identical to DataTable — they share useTableState. * * Props: DataTableProps & { pagination?: PaginationConfig } */ import * as React from "react" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "../ui/dropdown-menu" import { Tip } from "../ui/tip" import { TooltipProvider } from "../ui/tooltip" import { useSidebarReflowZoom } from "../../hooks/use-sidebar-reflow-zoom" import { cn } from "../../lib/utils" import { DataTable, type DataTableExtendedProps } from "./index" import type { PaginationConfig } from "./types" import type { useTableState } from "./use-table-state" // ───────────────────────────────────────────────────────────────────────────── // PaginationBar // ───────────────────────────────────────────────────────────────────────────── interface PaginationBarProps { page: number pageSize: number total: number pageSizeOptions: number[] onPageChange: (p: number) => void onPageSizeChange: (n: number) => void } export function PaginationBar({ page, pageSize, total, pageSizeOptions, onPageChange, onPageSizeChange, }: PaginationBarProps) { const reflowZoom = useSidebarReflowZoom() const totalPages = Math.max(1, Math.ceil(total / pageSize)) const from = Math.min((page - 1) * pageSize + 1, total) const to = Math.min(page * pageSize, total) const rangeLabel = total === 0 ? "0 results" : `${from}–${to} of ${total}` function handleKeyDown(e: React.KeyboardEvent) { if (e.key === "ArrowLeft" && page > 1) { e.preventDefault() onPageChange(page - 1) } else if (e.key === "ArrowRight" && page < totalPages) { e.preventDefault() onPageChange(page + 1) } } return (
No. of Row