import Box from '@mui/material/Box'; import IconButton from '@mui/material/IconButton'; import InputLabel from '@mui/material/InputLabel'; import MenuItem from '@mui/material/MenuItem'; import Pagination, { type PaginationProps } from '@mui/material/Pagination'; import PaginationItem from '@mui/material/PaginationItem'; import Select, { type SelectProps } from '@mui/material/Select'; import Tooltip from '@mui/material/Tooltip'; import Typography from '@mui/material/Typography'; import { useTheme } from '@mui/material/styles'; import useMediaQuery from '@mui/material/useMediaQuery'; import { type MRT_RowData, type MRT_TableInstance } from '../../types'; import { flipIconStyles, getCommonTooltipProps } from '../../utils/style.utils'; import { parseFromValuesOrFunc } from '../../utils/utils'; const defaultRowsPerPage = [5, 10, 15, 20, 25, 30, 50, 100]; export interface MRT_TablePaginationProps extends Partial< PaginationProps & { SelectProps?: Partial; disabled?: boolean; rowsPerPageOptions?: { label: string; value: number }[] | number[]; showRowsPerPage?: boolean; } > { position?: 'bottom' | 'top'; table: MRT_TableInstance; } export const MRT_TablePagination = ({ position = 'bottom', table, ...rest }: MRT_TablePaginationProps) => { const theme = useTheme(); const isMobile = useMediaQuery('(max-width: 720px)'); const { getState, options: { enableToolbarInternalActions, icons: { ChevronLeftIcon, ChevronRightIcon, FirstPageIcon, LastPageIcon }, id, localization, muiPaginationProps, paginationDisplayMode, }, } = table; const { pagination: { pageIndex = 0, pageSize = 10 }, } = getState(); const paginationProps = { ...parseFromValuesOrFunc(muiPaginationProps, { table, }), ...rest, }; const totalRowCount = table.getRowCount(); const numberOfPages = table.getPageCount(); const showFirstLastPageButtons = numberOfPages > 2; const firstRowIndex = pageIndex * pageSize; const lastRowIndex = Math.min(pageIndex * pageSize + pageSize, totalRowCount); const { SelectProps = {}, disabled = false, rowsPerPageOptions = defaultRowsPerPage, showFirstButton = showFirstLastPageButtons, showLastButton = showFirstLastPageButtons, showRowsPerPage = true, ...restPaginationProps } = paginationProps ?? {}; const disableBack = pageIndex <= 0 || disabled; const disableNext = lastRowIndex >= totalRowCount || disabled; if (isMobile && SelectProps?.native !== false) { SelectProps.native = true; } const tooltipProps = getCommonTooltipProps(); return ( {showRowsPerPage && ( {localization.rowsPerPage} )} {paginationDisplayMode === 'pages' ? ( table.setPageIndex(newPageIndex - 1)} page={pageIndex + 1} renderItem={(item) => ( )} showFirstButton={showFirstButton} showLastButton={showLastButton} {...restPaginationProps} /> ) : paginationDisplayMode === 'default' ? ( <> {`${ lastRowIndex === 0 ? 0 : (firstRowIndex + 1).toLocaleString(localization.language) }-${lastRowIndex.toLocaleString(localization.language)} ${ localization.of } ${totalRowCount.toLocaleString(localization.language)}`} {showFirstButton && ( table.firstPage()} size="small" > )} table.previousPage()} size="small" > table.nextPage()} size="small" > {showLastButton && ( table.lastPage()} size="small" > )} ) : null} ); };