How to show all rows with pagination overriding
See original GitHub issueHow to show all rows with pagination overriding
What to achieve
I want to have the option to set pageSize to ‘All’ to match to total count of rows in material-table.
What I have done
I use useState to create rowsPerPage , and set rowsPerPage in the handleChangeRowsPerPage function. I use component overriding to customize the Pagination and pass rowsPerPage and handler to its props. I also pass rowsPerPage to MaterialTable’s pageSize option.
Problems I encounter
The page does not re-size, and the state.pageSize does not update. Even though the props.options.pageSize and Pagination successfully update with onChangeRowsPerPage.
Link to sandbox
const handleChangeRowsPerPage = event => {
//enable to set rows per page to match total count
event.target.value === "All"
? setRowsPerPage(data.length)
: setRowsPerPage(event.target.value);
};
const data = [
{ name: "Mehmet", surname: "Baran", birthYear: 1987 },
{ name: "Zerya Betül", surname: "Baran", birthYear: 2017 }
];
return (
<MaterialTable
title="Component Override Demo"
columns={[
{ title: "Name", field: "name" },
{ title: "Surname", field: "surname" },
{ title: "Birth Year", field: "birthYear" }
]}
data={data}
//options.pageSize updates, but no re-size
options={{ pageSize: rowsPerPage }}
// onChangeRowsPerPage={handleChangeRowsPerPage} //TypeError Cannot read property 'value' of undefined
components={{
Pagination: props => (
<TablePagination
{...props}
rowsPerPageOptions={[5, 10, 20, "All"]}
rowsPerPage={rowsPerPage}
//updates pagination, but no re-size
onChangeRowsPerPage={handleChangeRowsPerPage}
/>
)
}}
/>
);
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:6 (1 by maintainers)
Top Results From Across the Web
my JavaFX TableView Pagination keep displaying all rows
My JavaFX table display pagination buttons number correctly but it keep displaying all rows,while I set the rows limit to 100, it detect...
Read more >Control pagination - Microsoft Support
If you are not in print layout view, on the View menu, click Print Layout. Do any of the following: Keep lines together....
Read more >Deferred loading of data - DataTables example
This automatic Ajax call to get the first page of data can be overridden by using the deferLoading initialisation property. It serves two...
Read more >Using material-table in React to build feature-rich data tables
To achieve this, the MaterialTable component takes an additional parameter named components where you can override almost any part of the table.
Read more >I am overriding the default pagination of MaterialTable as ...
However, the table always shows 5 rows even though the ... /56214292/any-example-for-custom-pagination-in-material-table-and-reactjs.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Please re-open this issue as I’m having a same problem which there’s no way to set pageSize programmatically
@NAkibRUET Thank you for reply! Yes, I confirmed that onChangeRowsPerPage as a props of MaterialTable takes event value as parameter. Now I am able to call my own handler inside onChangeRowsPerPage as
The problem persists because I cannot modify the pageSize state of MaterialTable.