Last active
July 16, 2021 14:40
-
-
Save wasuaje/fd3b6a2cd3a1cd704e60b07315644a62 to your computer and use it in GitHub Desktop.
Fix for error "_this.props.onChangePage is not a function at m-table-pagination.js:"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Source : https://github.com/mbrn/material-table/pull/2937 | |
import { TablePagination, TablePaginationProps } from '@material-ui/core'; | |
export default function PatchedPagination(props: TablePaginationProps) { | |
const { | |
ActionsComponent, | |
onChangePage, | |
onChangeRowsPerPage, | |
...tablePaginationProps | |
} = props; | |
return ( | |
<TablePagination | |
{...tablePaginationProps} | |
// @ts-expect-error onChangePage was renamed to onPageChange | |
onPageChange={onChangePage} | |
onRowsPerPageChange={onChangeRowsPerPage} | |
ActionsComponent={(subprops) => { | |
const { onPageChange, ...actionsComponentProps } = subprops; | |
return ( | |
// @ts-expect-error ActionsComponent is provided by material-table | |
<ActionsComponent | |
{...actionsComponentProps} | |
onChangePage={onPageChange} | |
/> | |
); | |
}} | |
/> | |
); | |
} | |
// later you use in the actual component file like: | |
import PatchedPagination from '../../components/PatchedPagination' | |
<MaterialTable | |
title={t("client_table_title")} | |
columns={[ | |
{ title: 'ID', field: 'id'}, | |
{ title: 'Name', field: 'name' }, | |
{ title: 'Phone', field: 'phone' }, | |
{ title: 'Email', field: 'email' }, | |
{ title: 'Address', field: 'address' }, | |
]} | |
// data={[ | |
// { name: 'Mehmet', surname: 'Baran', birthYear: 1987, birthCity: 63 }, | |
// { name: 'Zerya Betül', surname: 'Baran', birthYear: 2017, birthCity: 34 }, | |
// ]} | |
data = {data} | |
actions={[ | |
{ | |
icon: 'edit', | |
tooltip: 'Edit User', | |
onClick: (event, rowData) => handleFormOpen(rowData.id) | |
}, | |
{ | |
icon: 'delete', | |
tooltip: 'Delete User', | |
onClick: (event, rowData) => openDialogBox(rowData.id) | |
} | |
]} | |
options={{ | |
actionsColumnIndex: -1, | |
exportButton: true, | |
// paging: false | |
}} | |
components={{ | |
Pagination: PatchedPagination, | |
}} | |
/> | |
export default ClientTable; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment