-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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
[TablePagination] Out of range warning when "count={-1}" #19865
Labels
bug 🐛
Something doesn't work
component: table
This is the name of the generic UI component, not the React module!
good first issue
Great for first contributions. Enable to learn the contribution process.
Comments
oliviertassinari
added
bug 🐛
Something doesn't work
component: table
This is the name of the generic UI component, not the React module!
labels
Feb 26, 2020
oliviertassinari
changed the title
"Page prop of a TablePagination is out of range" when "count" prop is "-1"
[TablePagination] Out of range warning when "count={-1}"
Feb 26, 2020
@ilmiont Thanks for the report. What do you think of this patch? diff --git a/packages/material-ui/src/TablePagination/TablePagination.js b/packages/material-ui/src/TablePagination/TablePagination.js
index 62ce0ed12..5f75bc459 100644
--- a/packages/material-ui/src/TablePagination/TablePagination.js
+++ b/packages/material-ui/src/TablePagination/TablePagination.js
@@ -246,6 +246,11 @@ TablePagination.propTypes = {
*/
page: chainPropTypes(PropTypes.number.isRequired, props => {
const { count, page, rowsPerPage } = props;
+
+ if (count === -1) {
+ return null;
+ }
+
const newLastPage = Math.max(0, Math.ceil(count / rowsPerPage) - 1);
if (page < 0 || page > newLastPage) {
return new Error( Do you want to submit a pull request :)? |
oliviertassinari
added
the
good first issue
Great for first contributions. Enable to learn the contribution process.
label
Feb 26, 2020
1 task
@ilmiont I did Pull Request where we potentially fixed your problem. You can jump up too! :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug 🐛
Something doesn't work
component: table
This is the name of the generic UI component, not the React module!
good first issue
Great for first contributions. Enable to learn the contribution process.
Current Behavior 😯
The
count={-1}
should, per the documentation, indicate that the total count is unknown as we are (probably) using server-side pagination.I therefore expect to be able to use the next/previous page toggles (excepting previous when on page 1), without the component attempting to enforce an acceptable page range (as it has no way of knowing what that is).
When the
count={-1}
prop is present, and thepage
prop changes to anything other than0
, the following warning appears in the console:Warning: Failed prop type: Material-UI: the page prop of a TablePagination is out of range (0 to 0, but page is 1).
And despite purporting to be a warning, which I could somewhat tolerate, this is actually emitted as an error in the console.
Expected Behavior 🤔
When
count={-1}
, changing the page of theTablePagination
should not emit this warning/error.Steps to Reproduce 🕹
https://codesandbox.io/s/smoosh-cdn-ov0gg
Steps:
Your Environment 🌎
Material UI v4.9.4
The text was updated successfully, but these errors were encountered: