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

[data grid] How to deselect Row in onRowClick callback in DataGridPro? #14912

Open
MarcusKuehn opened this issue Oct 10, 2024 · 5 comments
Open
Labels
component: data grid This is the name of the generic UI component, not the React module! customization: logic Logic customizability enhancement This is not a bug, nor a new feature feature: Selection Related to the data grid Selection feature support: commercial Support request from paid users support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/

Comments

@MarcusKuehn
Copy link

MarcusKuehn commented Oct 10, 2024

The problem in depth

https://codesandbox.io/p/sandbox/admiring-thunder-m5nf8t

We wanted to build a small DataGrid, where you can select a Row and deselect it by simply left clicking. We thought we can just manipulate the selection with the details.api but found that we are than not able to deselect the row whatsoever (even with Ctrl+leftClick).

Is it even possible to manipulate the default Behaviour of the DataGrid that you can select/deselect a row by just left clicking?

Your environment

`npx @mui/envinfo`
System:
    OS: macOS 15.0.1
  Binaries:
    Node: 20.15.0 - ~/Library/pnpm/node
    npm: 10.7.0 - ~/Library/pnpm/npm
    pnpm: 9.11.0 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 129.0.6668.91
    Edge: 129.0.2792.79
    Safari: 18.0.1
  npmPackages:
    @emotion/react: ^11.13.3 => 11.13.3 
    @emotion/styled: ^11.13.0 => 11.13.0 
    @mui/icons-material: ^6.1.3 => 6.1.3 
    @mui/lab: 6.0.0-beta.10 => 6.0.0-beta.10 
    @mui/material: ^6.1.3 => 6.1.3 
    @mui/x-charts-pro: 7.0.0-beta.3 => 7.0.0-beta.3 
    @mui/x-data-grid-pro: 7.19.0 => 7.19.0 
    @mui/x-date-pickers-pro: 7.19.0 => 7.19.0 
    @mui/x-license: ^7.18.0 => 7.18.0 
    @mui/x-tree-view-pro: ^7.19.0 => 7.19.0 
    @toolpad/core: ^0.7.0 => 0.7.0 
    @types/react: ^18.3.10 => 18.3.10 
    react: ^18.3.1 => 18.3.1 
    react-dom: ^18.3.0 => 18.3.1 
    typescript: ^5.6.3 => 5.6.3 

Search keywords: DataGrid
Order ID: 85157

@MarcusKuehn MarcusKuehn added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Oct 10, 2024
@github-actions github-actions bot added component: data grid This is the name of the generic UI component, not the React module! support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/ labels Oct 10, 2024
@cherniavskii
Copy link
Member

Hi @MarcusKuehn
It seems that after you manipulate row selection in the onRowClick handler, the default handler kicks in and keeps the row selected.
For custom selection behavior, I would recommend using the controlled row selection model.
Here is a working demo: https://codesandbox.io/p/sandbox/old-firefly-m4xw49
Is this what you're looking for?

@cherniavskii cherniavskii added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 10, 2024
@cherniavskii
Copy link
Member

I feel like it would make sense to make the row deselection on click a default behavior 🤔
What do you think @mui/xgrid ?

@cherniavskii cherniavskii added feature: Selection Related to the data grid Selection feature customization: logic Logic customizability labels Oct 10, 2024
@MarcusKuehn
Copy link
Author

Hi @MarcusKuehn It seems that after you manipulate row selection in the onRowClick handler, the default handler kicks in and keeps the row selected. For custom selection behavior, I would recommend using the controlled row selection model. Here is a working demo: https://codesandbox.io/p/sandbox/old-firefly-m4xw49 Is this what you're looking for?

This is exactly what we were looking for. Thanks for the fast reply.

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Oct 11, 2024
@michelengelen
Copy link
Member

I feel like it would make sense to make the row deselection on click a default behavior 🤔 What do you think @mui/xgrid ?

Since everybody seemingly agrees I'll add this to the board! 👍🏼

@michelengelen michelengelen removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 11, 2024
@github-project-automation github-project-automation bot moved this to 🆕 Needs refinement in MUI X Data Grid Oct 11, 2024
@michelengelen michelengelen added the enhancement This is not a bug, nor a new feature label Oct 11, 2024
@michelengelen michelengelen changed the title [question] How to deselect Row in onRowClick callback in DataGridPro? [data grid] How to deselect Row in onRowClick callback in DataGridPro? Oct 11, 2024
@cherniavskii
Copy link
Member

Added to #13188

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! customization: logic Logic customizability enhancement This is not a bug, nor a new feature feature: Selection Related to the data grid Selection feature support: commercial Support request from paid users support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/
Projects
Status: 🆕 Needs refinement
Development

No branches or pull requests

3 participants