mui-x icon indicating copy to clipboard operation
mui-x copied to clipboard

[DataGrid] Controlled selection throws warning if more than one selected when rendering checkbox with `gridCheckboxSelectionColDef`

Open alb7h opened this issue 5 years ago • 4 comments

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

Current Behavior 😯

Selection warning triggers when more than one is selected

Expected Behavior 🤔

It should not trigger a warning

Steps to Reproduce 🕹

https://codesandbox.io/s/xenodochial-lehmann-pzlhx?file=/src/Demo.tsx

Steps:

  1. Select more than one on either side
  2. See warning in console

Context 🔦

Essentially I'm trying to change the location of the checkbox which is why I'm not using checkboxSelection since it forces its own location. A secondary issue is that I don't want the select all checkbox which leads me to wanting to control the checkbox column myself.

Honestly, I think I can just get by without this being a controlled selection since I only need to know what's been selected, and that doesn't throw any errors, but this problem felt weird enough to raise an issue.

Your Environment 🌎

`npx @material-ui/envinfo`
npx: installed 2 in 0.884s

  System:
    OS: macOS 11.4
  Binaries:
    Node: 14.17.3 - ~/.volta/tools/image/node/14.17.3/bin/node
    Yarn: 3.0.0-rc.9 - ~/.volta/tools/image/yarn/1.22.10/bin/yarn
    npm: 6.14.13 - ~/.volta/tools/image/node/14.17.3/bin/npm
  Browsers:
    Chrome: 92.0.4515.131
    Edge: Not Found
    Firefox: Not Found
    Safari: 14.1.1
  npmPackages:
    @emotion/react:  11.4.0 
    @emotion/styled:  11.3.0 
    @material-ui/core:  5.0.0-beta.4 
    @material-ui/data-grid:  4.0.0-alpha.37 
    @material-ui/icons:  5.0.0-beta.4
    @material-ui/lab:  5.0.0-alpha.43 
    @material-ui/private-theming:  5.0.0-beta.4 
    @material-ui/styled-engine:  5.0.0-beta.4 
    @material-ui/styles:  5.0.0-beta.4 
    @material-ui/system:  5.0.0-beta.4 
    @material-ui/types:  6.0.2 
    @material-ui/unstyled:  5.0.0-alpha.43 
    @material-ui/utils:  5.0.0-beta.4 
    @material-ui/x-grid:  4.0.0-alpha.37 
    @material-ui/x-license:  4.0.0-alpha.37 
    @types/react:  17.0.15 
    react:  17.0.2 
    react-dom:  17.0.2 
    typescript:  4.3.5 

Order id 💳

alb7h avatar Aug 17 '21 14:08 alb7h

It is because gridCheckboxSelectionColDef by default renders a checkbox cell at: https://github.com/mui-org/material-ui-x/blob/aa9922f68b987ce0fe721fccd93c7227278ea098/packages/grid/modules/grid/models/colDef/gridCheckboxSelection.tsx#L23 and the checkboxSelection prop is not being passed which triggered the warning, https://github.com/mui-org/material-ui-x/blob/aa9922f68b987ce0fe721fccd93c7227278ea098/packages/grid/data-grid/src/DataGridPropTypes.ts#L193-L206

Maybe we need to have an option to set the location of checkbox column without using gridCheckboxSelectionColDef but only using checkboxSelection prop.

ZeeshanTamboli avatar Aug 17 '21 15:08 ZeeshanTamboli

@ZeeshanTamboli To add to line location information:

https://github.com/mui-org/material-ui-x/blob/086715700df11e01e5a08e83abe69155a1c02664/packages/grid/modules/grid/hooks/features/columns/useGridColumns.ts#L99-L103

The only solution I can compare this to is AG Grid, where this sort of thing is handled on the column definition instead by specifying a checkboxSelection / headerCheckboxSelection attribute. I'm a little bit more of a fan of this personally as I'd prefer to be more explicit than implicit and it allows me to modify the column checkbox as needed.

alb7h avatar Aug 17 '21 15:08 alb7h

Multiple selection without the checkboxSelection prop is only available in DataGridPro: https://material-ui.com/components/data-grid/selection/#multiple-row-selection

You could also create your own checkbox, without reusing gridCheckboxSelectionColDef and implement all the selection behavior.

Maybe we need to have an option to set the location of checkbox column without using gridCheckboxSelectionColDef but only using checkboxSelection prop.

+1 for this. It could be checkboxSelectionPosition: start | end or change checkboxSelection to accept the position instead of a boolean. I suppose users speaking RTL languages would need it too.

m4theushw avatar Aug 17 '21 15:08 m4theushw

The problem does not exist anymore

https://codesandbox.io/s/data-grid-community-forked-ckdq0s

You can see this doc section to custimize the position of the column

flaviendelangle avatar Jun 29 '22 11:06 flaviendelangle