import { Button } from "../button"; import { DataTableFooterProps } from "./types"; export interface DataTableFooterOptions { pageSizeOptions?: number[]; showPageSizeSelector?: boolean; showRowCount?: boolean; showPagination?: boolean; labels?: { rowsPerPage?: string; page?: string; of?: string; showing?: string; ofLabel?: string; items?: string; previous?: string; next?: string; }; } interface DataTableFooterComponentProps< TData, > extends DataTableFooterProps { options?: DataTableFooterOptions; } const defaultOptions: DataTableFooterOptions = { pageSizeOptions: [5, 10, 25, 50], showPageSizeSelector: true, showRowCount: true, showPagination: true, labels: { rowsPerPage: "Rows per page", page: "Page", of: "of", showing: "Showing", ofLabel: "of", items: "items", previous: "Previous", next: "Next", }, }; export function DataTableFooter({ table, pagination, options = {}, }: DataTableFooterComponentProps) { const opts = { ...defaultOptions, ...options }; const labels = { ...defaultOptions.labels, ...options.labels }; const pageIndex = pagination.pageIndex ?? 0; const pageSize = pagination.pageSize ?? 10; const totalCount = pagination.totalCount ?? 0; const start = totalCount === 0 ? 0 : pageIndex * pageSize + 1; const end = Math.min((pageIndex + 1) * pageSize, totalCount); const handlePageSizeChange = (newPageSize: number) => { table?.setPageSize(newPageSize); }; return (
{(opts.showPageSizeSelector || opts.showRowCount) && (
{opts.showPageSizeSelector && ( <> )} {opts.showRowCount && ( {labels.showing} {start}–{end} {labels.ofLabel} {totalCount}{" "} {labels.items} )}
)} {opts.showPagination && (
)}
); }