Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add disabled props to TablePagination #858

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const defaultRowsPerPage = [5, 10, 15, 20, 25, 30, 50, 100];
interface Props<TData extends MRT_RowData>
extends Partial<
PaginationProps & {
disabled?: boolean;
rowsPerPageOptions?: { label: string; value: number }[] | number[];
showRowsPerPage?: boolean;
}
Expand Down Expand Up @@ -61,6 +62,7 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({

const {
SelectProps,
disabled = false,
rowsPerPageOptions = defaultRowsPerPage,
showFirstButton = showFirstLastPageButtons,
showLastButton = showFirstLastPageButtons,
Expand Down Expand Up @@ -97,6 +99,7 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
</InputLabel>
<Select
disableUnderline
disabled={disabled}
id="mrt-rows-per-page"
inputProps={{ 'aria-label': localization.rowsPerPage }}
label={localization.rowsPerPage}
Expand Down Expand Up @@ -129,6 +132,7 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
{paginationDisplayMode === 'pages' ? (
<Pagination
count={numberOfPages}
disabled={disabled}
onChange={(_e, newPageIndex) => setPageIndex(newPageIndex - 1)}
page={pageIndex + 1}
renderItem={(item) => (
Expand Down Expand Up @@ -162,7 +166,7 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
{showFirstButton && (
<IconButton
aria-label={localization.goToFirstPage}
disabled={pageIndex <= 0}
disabled={pageIndex <= 0 || disabled}
onClick={() => setPageIndex(0)}
size="small"
>
Expand All @@ -171,15 +175,15 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
)}
<IconButton
aria-label={localization.goToPreviousPage}
disabled={pageIndex <= 0}
disabled={pageIndex <= 0 || disabled}
onClick={() => setPageIndex(pageIndex - 1)}
size="small"
>
<ChevronLeftIcon />
</IconButton>
<IconButton
aria-label={localization.goToNextPage}
disabled={lastRowIndex >= totalRowCount}
disabled={lastRowIndex >= totalRowCount || disabled}
onClick={() => setPageIndex(pageIndex + 1)}
size="small"
>
Expand All @@ -188,7 +192,7 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
{showLastButton && (
<IconButton
aria-label={localization.goToLastPage}
disabled={lastRowIndex >= totalRowCount}
disabled={lastRowIndex >= totalRowCount || disabled}
onClick={() => setPageIndex(numberOfPages - 1)}
size="small"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,17 @@ export const CustomizePaginationComponents = () => (
}}
/>
);

export const DisabledPaginationComponents = () => (
<MaterialReactTable
columns={columns}
data={data}
initialState={{ pagination: { pageIndex: 0, pageSize: 5 } }}
muiPaginationProps={{
disabled: true,
rowsPerPageOptions: [5, 10, 20],
showFirstButton: false,
showLastButton: false,
}}
/>
);