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] Treedata expand/collapse does not trigger onRowClick-Event #11655

Closed
GeiOoo opened this issue Jan 11, 2024 · 8 comments
Closed

[DataGrid] Treedata expand/collapse does not trigger onRowClick-Event #11655

GeiOoo opened this issue Jan 11, 2024 · 8 comments
Labels
component: data grid This is the name of the generic UI component, not the React module! feature: Tree data Related to the data grid Tree data feature

Comments

@GeiOoo
Copy link

GeiOoo commented Jan 11, 2024

Steps to reproduce

Video: https://github.com/mui/mui-x/assets/29431488/c4fe3ae8-2661-4640-bde0-b8022c09ce3b
Link to live example: https://stackblitz.com/edit/react-qwvzzk?file=Demo.tsx

Steps:

  1. Click the row anywhere to trigger this handle -> log in console appears
  2. Click the collapse/expand button in the grouping column -> no logging in console

Current behavior

The collapse/expand button does not trigger the onRowClick event.

Expected behavior

The collapse/expand button should trigger the onRowClickEvent to also react to state changes on this row.

Context

I have to save the current collapsed/expanded state of all grouping rows. This onRowClick event would be a solution for that since there is no separate event listener for state changes of row grouping collapse/expande.

If habe also posted a separate feature request for that: #11654

Your environment

npx @mui/envinfo
  System:
    OS: Windows 11 10.0.22621
  Binaries:
    Node: 20.9.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.1.0 - C:\Program Files\nodejs\npm.CMD
    pnpm: Not Found
  Browsers:
    Chrome: 120.0.6099.201
    Edge: Chromium (120.0.2210.121)
  npmPackages:
    @emotion/react: ^11.11.3 => 11.11.3 
    @emotion/styled: ^11.11.0 => 11.11.0 
    @mui/base:  5.0.0-beta.31 
    @mui/core-downloads-tracker:  5.15.4 
    @mui/icons-material: ^5.15.4 => 5.15.4 
    @mui/material: ^5.15.4 => 5.15.4 
    @mui/private-theming:  5.15.4 
    @mui/styled-engine:  5.15.4 
    @mui/system:  5.15.4 
    @mui/types:  7.2.13
    @mui/utils:  5.15.4
    @mui/x-data-grid:  6.18.7
    @mui/x-data-grid-pro: ^6.18.7 => 6.18.7
    @mui/x-date-pickers: ^6.18.7 => 6.18.7
    @mui/x-license-pro:  6.10.2
    @types/react: ^18.2.47 => 18.2.47
    react: ^18.2.0 => 18.2.0
    react-dom: ^18.2.0 => 18.2.0
    typescript: ^5.3.3 => 5.3.3

Search keywords: datagrid treedata group expand collapse row

@GeiOoo GeiOoo added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 11, 2024
@evgeniiarts
Copy link

@GeiOoo I think the onRowClick event is designed for purposes where you interact with the row as a dataset, but not as a visual element. Because we can retrieve the row id and it's data when clicking it from the event. Therefore I think the expansion toggle has an e.preventDefault to avoid it. As it is commonly used for row selection, you probably do not want to select a row when expanding it.. Or open a side layer with detailed information and so on.
Maybe your main motivation can be solved in a different way? See my comment on #11654
:)

@michelengelen
Copy link
Member

Hey @GeiOoo ... we do have a section on the docs that (kind of) handles this already by subscribing a handler to the 'rowExpansionChange' event: Lazy loading children

The param in this is the node that gets expanded, so you can easily get the rowdata with const row = apiRef.current.getRow(node.id) as Row | null;

@evgeniiarts
Copy link

Hehe apparently I still have a lot to learn, thanks @michelengelen for pointing that out :)

@michelengelen michelengelen added component: data grid This is the name of the generic UI component, not the React module! status: waiting for author Issue with insufficient information feature: Tree data Related to the data grid Tree data feature and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 11, 2024
@michelengelen michelengelen self-assigned this Jan 11, 2024
@michelengelen
Copy link
Member

Hehe apparently I still have a lot to learn, thanks @michelengelen for pointing that out :)

don't worry ... that's a pretty advance use-case! :D

@flaviendelangle
Copy link
Member

flaviendelangle commented Jan 11, 2024

I think onRowClick is not called because of this event.stopPropagation https://github.com/mui/mui-x/blob/next/packages/grid/x-data-grid-pro/src/components/GridTreeDataGroupingCell.tsx#L59

It was added in #3929

Copy link

The issue has been inactive for 7 days and has been automatically closed. If you think that it has been incorrectly closed, please reopen it and provide missing information (if any) or continue the last discussion.

@flaviendelangle flaviendelangle removed the status: waiting for author Issue with insufficient information label Jan 18, 2024
@flaviendelangle
Copy link
Member

@michelengelen I reopened it because it was unclear to me if we had to wait for user feedbacks on that one, feel free to re-close it if you want

@michelengelen michelengelen removed their assignment Feb 28, 2024
Copy link

⚠️ This issue has been closed.
If you have a similar problem, please open a new issue and provide details about your specific problem.
If you can provide additional information related to this topic that could help future readers, please feel free to leave a comment.

How did we do @GeiOoo?
Your experience with our support team matters to us. If you have a moment, please share your thoughts through our brief survey.

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! feature: Tree data Related to the data grid Tree data feature
Projects
None yet
Development

No branches or pull requests

4 participants