Skip to content
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] change to selectionModel prop results in onSelectionModelChange to be invoked #2136

Closed
2 tasks done
mindtraveller opened this issue Jul 12, 2021 · 2 comments
Closed
2 tasks done
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module!

Comments

@mindtraveller
Copy link

mindtraveller commented Jul 12, 2021

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

When the controlled version of selection management is used onSelectionModelChange callback is invoked when selectionModel changes.

Expected Behavior 🤔

The change to input prop should not cause an *OnChange callback to be invoked e.g. controlled inputs don't work in that way.

I would not expect onSelectionModelChange to be invoked when selectionModel prop changes.

Steps to Reproduce 🕹

Steps:

  1. use the example from docs https://material-ui.com/components/data-grid/selection/#controlled-selection
  2. update selectionModel outside of the table itself e.g. the button which selects all rows.
  3. the onSelectionModelChange callback is invoked after selectionModel prop has changed.

Context 🔦

In our example, we have lazy-loaded table when the 'select all' checkbox selects only already loaded part of that table (the default behaviour). We're adding the kind of button by clicking which list turns into complete select all mode which means that all items are selected even those that are not loaded in the table right now. In that mode we have to automatically select items as they are getting loaded during scrolling.

Your Environment 🌎

`npx @material-ui/envinfo`
System:
    OS: macOS 11.4
  Binaries:
    Node: 14.15.3 - ~/.asdf/installs/nodejs/14.15.3/bin/node
    Yarn: 1.15.2 - /usr/local/bin/yarn
    npm: 6.14.9 - ~/.asdf/installs/nodejs/14.15.3/bin/npm
  Browsers:
    Chrome: 91.0.4472.114
    Edge: Not Found
    Firefox: 87.0
    Safari: 14.1.1
  npmPackages:
    @material-ui/core: 4.11.1 => 4.11.1 
    @material-ui/icons: 4.5.1 => 4.5.1 
    @material-ui/lab: 4.0.0-alpha.56 => 4.0.0-alpha.56 
    @material-ui/pickers: 3.1.2 => 3.1.2 
    @material-ui/styles: 4.11.1 => 4.11.1 
    @material-ui/system:  4.11.3 
    @material-ui/types:  5.1.0 
    @material-ui/utils:  4.11.2 
    @types/react:  17.0.0 
    react: 16.12.0 => 16.12.0 
    react-dom: 16.12.0 => 16.12.0 
    typescript: 4.2.3 => 4.2.3 

  Browser:
    Google Chrome Version 91.0.4472.114

Order id 💳

#27213

@mindtraveller mindtraveller added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jul 12, 2021
@mindtraveller mindtraveller changed the title [XGrid] change to selectionModel prop results in onSelectionModelChange getting invoked [XGrid] change to selectionModel prop results in onSelectionModelChange to be invoked Jul 12, 2021
@dtassone dtassone added bug 🐛 Something doesn't work and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jul 12, 2021
@oliviertassinari
Copy link
Member

oliviertassinari commented Jul 17, 2021

@dtassone Please keep the "status: needs triage" label if you are not looking at what's going wrong.


A reproduction of the issue with v4.0.0-alpha.33: https://codesandbox.io/s/material-demo-forked-fvgcx?file=/package.json:399-413, the latest version.

A proof that #1823 fixes it: https://codesandbox.io/s/material-demo-forked-v7uhf?file=/package.json. So it's fixed on HEAD, and we have test cases. The next release will contain the fix.

@oliviertassinari oliviertassinari added the component: data grid This is the name of the generic UI component, not the React module! label Jul 17, 2021
@oliviertassinari oliviertassinari changed the title [XGrid] change to selectionModel prop results in onSelectionModelChange to be invoked [DataGrid] change to selectionModel prop results in onSelectionModelChange to be invoked Jul 17, 2021
@DCMattyG
Copy link

I'm seeing this behavior in v5.8.0, is this going to be fixed? I have logic in my "onSelectionModelChange" callback that I don't want triggered if I update the selectionModel from outside the Data Grid.

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: data grid This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

4 participants