'use client'; import { Table } from '@tanstack/react-table'; import clsx from 'clsx'; import { useCallback } from 'react'; import { BiChevronLeft, BiChevronRight, BiFirstPage, BiLastPage } from 'react-icons/bi'; import { prefixes } from '@/utils/constants'; interface PaginationToolsProps { table: Table paginationOptions: number[] onChangePaginationOption?: (newValue: number) => void } function PaginationTools({ table, paginationOptions, onChangePaginationOption }: PaginationToolsProps) { const handlePaginationOptionsChange = useCallback( (event: React.ChangeEvent) => { const perPage = Number(event.target.value); table.setPageSize(perPage); if (onChangePaginationOption) { onChangePaginationOption(perPage); } }, [onChangePaginationOption, table]); return (
{`${table.getState().pagination.pageIndex * table.getState().pagination.pageSize + 1} - ${Math.min(table.getFilteredRowModel().rows.length, (table.getState().pagination.pageIndex + 1) * table.getState().pagination.pageSize)} из ${table.getFilteredRowModel().rows.length}`}
{ const page = event.target.value ? Number(event.target.value) - 1 : 0; if (page + 1 <= table.getPageCount()) { table.setPageIndex(page); } }} />
); } export default PaginationTools;