-
-
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
[DataGrid] Changing pages causes onSelectionModelChange prop to be invoked #4676
Comments
I tried to reproduce the steps in the example you provided but I ended on a different result. When switching back to the first page, it shows "10 rows selected" but called
|
I reproduced the behavior I saw in the OP. Decided to make a video: Kapture.2022-04-29.at.08.02.35.mp4Are we seeing a difference in behavior because it's pulling in different versions? What I see locally matches the behavior I see in the codesandbox. |
@m4theushw I am happy to contribute a fix for this. We would just need to discuss what the correct behavior should be before I begin implementation. |
If I go a couple more pages then I see the empty row count. This bug happens in part because the way this specific demo was built but also due to the fact that the grid always tries to sanitize the selection model, keeping in it only the rows that exist in the In our demo, there's a One way to fix this would be introduce a prop to allow in diff --git a/packages/grid/x-data-grid/src/hooks/features/selection/useGridSelection.ts b/packages/grid/x-data-grid/src/hooks/features/selection/useGridSelection.ts
index a2bb5eac4..7c661724d 100644
--- a/packages/grid/x-data-grid/src/hooks/features/selection/useGridSelection.ts
+++ b/packages/grid/x-data-grid/src/hooks/features/selection/useGridSelection.ts
@@ -265,6 +265,10 @@ export const useGridSelection = (
* EVENTS
*/
const removeOutdatedSelection = React.useCallback(() => {
+ if (props.keepNonExistentRowsSelected) {
+ return;
+ }
+
const currentSelection = gridSelectionStateSelector(apiRef.current.state);
const rowsLookup = gridRowsLookupSelector(apiRef); Then it would be up to you to clean |
That seems like a reasonable change. Would you like me to open a PR with those changes? |
Feel free to open a PR proposing the change, or we can leave for someone from the X team or community. To test the new prop we only need to create a test case based on the below one but with the behavior inverted: mui-x/packages/grid/x-data-grid/src/tests/selection.DataGrid.test.tsx Lines 560 to 561 in e7f9f56
|
Opened #4786 |
Hi @willsoto, How can we fix this issue for MUI v4? So is there any workaround with refs? |
Hi @ozanmanav, Did you get the solution for MUI V4? |
Duplicates
Latest version
Current behavior 😯
The current behavior makes it so that a controlled selection is getting "blown away" when the page changes thus making retaining the
selectionModel
difficult / impossible. I am following the example in the documentation and am on version5.10.0
Demo taken from the documentation with a
console.log
added to show state is not being retained when changing pages:https://codesandbox.io/s/controlledselectionserverpaginationgrid-material-demo-forked-6whmr8?file=/demo.tsx
Seems like it may be a regression or related to #2136
Expected behavior 🤔
When the page changes, the selection model callback should either:
Steps to reproduce 🕹
https://codesandbox.io/s/controlledselectionserverpaginationgrid-material-demo-forked-6whmr8?file=/demo.tsx
Follow the steps / code described in the documented example to see that it no longer works when opened separately (although it is unclear to me why it seems to be working on the documentation itself)
I have added
console.log
statements so you can see theonSelectionModelChange
callsContext 🔦
I am trying to retain selections when changing pages using server side pagination.
Your environment 🌎
`npx @mui/envinfo`
Using Firefox: 99.0.1
Order ID 💳 (optional)
No response
The text was updated successfully, but these errors were encountered: