-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[data-grid] Controlled pagination issue #3516
Comments
This sounds more like protection than a bug. In your example A solution is to check in onPageSizeChange={(pageSize) => {
console.log("Current Page Size: ", pageSize);
setSelectedPageSize(pageSize);
const lastPageIndex = Math.max(
0,
Math.floor((ROW_NUMBER - 1) / pageSize)
);
if (selectedPage > lastPageIndex) {
setSelectedPage(lastPageIndex);
}
}} You can experiment it in the following code sandbox: https://codesandbox.io/s/happy-brook-cmity?file=/src/Demo.tsx @mui-org/x I'm wondering if we should display a warning when the page is out of the range. For example, it could be
Another solution would be to add a warning in the doc |
Hmm. Your example is helpful and makes sense but technically since we switch to controlled pagination then we should be responsible to update page explicitly just like you did in your example code. Also your sandbox example works as expected on online playground but locally I have much more props on grid then the example code, I have directly pasted the code from your example but still get the same issue. I am debugging the issue will update if find any. Thanks. |
@cq-ubaid-khan I didn't understand what you meant here. The callback gives the new value and you're responsible for saving it in the state or not.
@alexfauquette Do you mean when the user changes the page size to value that causes the current page to be out of range? If so, this's not an user's fault and warnings only appear in development mode. However, passing the reason for the page to have change might be useful. Looking back to the issue, if users try to implement a server-side pagination as explained in this demo they will make two ajax requests when changing the page size to a value that also causes a page change. Here's an CodeSandbox showing the problem. Click 3 times in the next page button, then change the page size to 20. The effect is called twice. I think there would be a |
@m4theushw Yes for both:
Thanks for the CodeSandox which illustrates well the problem. I think |
Thanks for addressing this issue. I am still struggling with this issue and since you understand the problem, Is there any possible solutions to tackle this problem or do you have plan of adding Thanks. |
Concerning You can group the update with a |
Duplicates
Latest version
Current behavior 😯
I have a controlled pagination with
onPageChange
andonPageSizeChange
functions applied on datagrid and pagination mode sets to "server", But sometimes when changingpageSize
theonPageSizeChange
is called butonPageChange
also gets called automatically.Expected behavior 🤔
I am expecting that both the
onPageChange
andonPageSizeChange
functions should work independently.Steps to reproduce 🕹
https://codesandbox.io/s/quirky-tu-i0nox?file=/src/Demo.tsx
Steps:
You will probably see the output something like this
Output:
Current Page Size: 10
Current Page: 2
Context 🔦
I have ajax calls in both functions and currently same ajax calls are being sent multiple times and page state also gets reverted to old state.
Your environment 🌎
`npx @mui/envinfo`
The text was updated successfully, but these errors were encountered: