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] Improve support for DataGrid inside DataGrid #4243

Closed
2 tasks done
C-Pettersson opened this issue Mar 20, 2022 · 10 comments
Closed
2 tasks done

[data-grid] Improve support for DataGrid inside DataGrid #4243

C-Pettersson opened this issue Mar 20, 2022 · 10 comments
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module!

Comments

@C-Pettersson
Copy link

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

Pressing a cell shouldn't return an error saying the column is undefined.

Expected behavior 🤔

Cell should be selected or at least no error.

Steps to reproduce 🕹

codesandbox:
Link

Steps:

  1. Go to codesandbox
  2. Press Open on row id 1
  3. Click on the cell for Kiwi-value
  4. You are prompted with an error

Context 🔦

I'm trying to show additional information in a Modal

Your environment 🌎

`npx @mui/envinfo`
System:
    OS: Windows 10 10.0.19044
  Binaries:
    Node: 16.14.2 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.11 - C:\Program Files\nodejs\yarn.CMD
    npm: 7.23.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 99.0.4844.74
    Edge: Spartan (44.19041.1266.0), Chromium (99.0.1150.46)
  npmPackages:
    @emotion/react: ^11.8.1 => 11.8.2
    @emotion/styled: ^11.8.1 => 11.8.1
    @mui/base:  5.0.0-alpha.72
    @mui/icons-material: ^5.5.0 => 5.5.1
    @mui/material: ^5.5.0 => 5.5.1
    @mui/private-theming:  5.4.4
    @mui/styled-engine:  5.4.4
    @mui/system:  5.5.1
    @mui/types:  7.1.3
    @mui/utils:  5.4.4
    @mui/x-data-grid: ^5.6.0 => 5.6.1
    @types/react:  17.0.40
    react: ^17.0.2 => 17.0.2
    react-dom: ^17.0.2 => 17.0.2

Order ID 💳 (optional)

No response

@C-Pettersson C-Pettersson added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Mar 20, 2022
@C-Pettersson C-Pettersson changed the title Cellclick return Column is undefined [DataGrid] Cellclick return Column is undefined Mar 20, 2022
@m4theushw
Copy link
Member

You need to stop the propagation of the click event in the modal.

<div onClick={(event) => event.stopPropagation()}
  <DataGrid />
</div>

Here's the updated CodeSandbox: https://codesandbox.io/s/debug-modal-with-datagrid-forked-uvnqds?file=/src/TinyInfo.tsx:324-384

@m4theushw m4theushw added component: data grid This is the name of the generic UI component, not the React module! status: expected behavior Does not imply the behavior is intended. Just that we know about it and can't work around it and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Mar 21, 2022
@m4theushw m4theushw changed the title [DataGrid] Cellclick return Column is undefined [DataGrid] Dialog inside cell crashes when clicked Mar 21, 2022
@m4theushw m4theushw changed the title [DataGrid] Dialog inside cell crashes when clicked [DataGrid] Modal inside cell crashes when clicked Mar 21, 2022
@C-Pettersson
Copy link
Author

C-Pettersson commented Mar 22, 2022

Thanks for the solution, really appreciate it. Is this something I'm expected to know? If so, how would one go about figure it out?

@m4theushw
Copy link
Member

Is this something I'm expected to know?

No, this use case was tricky because is a DataGrid inside another DataGrid, considering the React tree. If you render any other component, not a DataGrid, it won't crash.

I updated the label because there's an opportunity to improve the support for DataGrid inside DataGrid. The following function returns the incorrect element.

const publishClick = React.useCallback(
(event) => {
const cell = findParentElementFromClassName(event.target, gridClasses.cell);

When one cell from the child DataGrid is clicked, publishClick is called twice: first in the child grid and again in the "master" grid. In the click inside the master instance, event.target still refers to the child grid so it gets the wrong field name.

@m4theushw m4theushw added bug 🐛 Something doesn't work and removed status: expected behavior Does not imply the behavior is intended. Just that we know about it and can't work around it labels Mar 23, 2022
@m4theushw m4theushw changed the title [DataGrid] Modal inside cell crashes when clicked [DataGrid] Improve support for DataGrid inside DataGrid Mar 23, 2022
@C-Pettersson
Copy link
Author

Thanks for the explanation. Guess that's what you get for liking DataGrid too much, putting DataGrid in DataGrid 😄

@flaviendelangle flaviendelangle changed the title [DataGrid] Improve support for DataGrid inside DataGrid [data-grid] Improve support for DataGrid inside DataGrid Mar 28, 2022
@akshaylive
Copy link

Stopping event propagation completely will mess up editable columns in the child DataGrid. Here's an alternative solution to fix this:

onClick={(event) => event.target = document.body}

@jorge-ardila
Copy link

Is there any progress on this solution?

@kennyma-eplus
Copy link

kennyma-eplus commented Aug 15, 2023

Can't believe this bug won't fix after a year
I still need to use onClick={(event) => event.target = document.body} for workaround

But i am not sure if this workaround will affect anything about <Dialog/>

@colespencer1453
Copy link

@m4theushw I'm having issues with some edit interactions in this use case when using your proposed solution. The solution proposed by others shown below does fix the issue, but I was wondering if you know of any reasons this could be potentially dangerous or introduce side effects?

onClick={(event) => event.target = document.body}

@cherniavskii
Copy link
Member

The issue is fixed in Data Grid v7: https://stackblitz.com/edit/react-s3awys?file=Demo.tsx

@cherniavskii cherniavskii moved this from 🆕 Needs refinement to ✅ Done in MUI X Data Grid Apr 9, 2024
Copy link

github-actions bot commented Apr 9, 2024

⚠️ This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

@C-Pettersson: How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

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
Status: Done
Development

No branches or pull requests

7 participants