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 disable collapse button for DataGrid Master detail conditionally? #13108

Open
sanlee13 opened this issue May 13, 2024 · 8 comments
Labels
customization: extend Logic customizability feature: Master-detail Related to the data grid Master-detail feature recipe support: commercial Support request from paid users support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/ waiting for 👍 Waiting for upvotes

Comments

@sanlee13
Copy link

sanlee13 commented May 13, 2024

The problem in depth

Hello,

I have a DataGrid that makes use of the master details, when I expand a row, I display an edit button which toggles an edit mode flag, when the edit mode is enabled, I want the collapse button to be disabled and removed to prevent the user from clicking it by mistake. This seems like a trivial task but am unable to find a way to do this.

Thanks for your time

Your environment

`npx @mui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: disable collapse button for DataGrid Master detail.
Order ID: 82571

@sanlee13 sanlee13 added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels May 13, 2024
@michelengelen michelengelen added the support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/ label May 14, 2024
@michelengelen michelengelen changed the title How to disable collapse button for DataGrid Master detail conditionally? [data grid] How to disable collapse button for DataGrid Master detail conditionally? May 14, 2024
@michelengelen
Copy link
Member

Hey @sanlee13
Is the edit mode triggering the cell/row edit mode?
Or is it a custom state inside the master detail content?

To accomplish this you would need to pass a custom cell renderer to the toggle column and find a way to pass the edit state from your master detail to that toggle renderer.

Could you maybe provide us with a minimal reproduction demo in codesandbox or stackblitz? That would help a lot!

@michelengelen michelengelen added status: waiting for author Issue with insufficient information customization: extend Logic customizability feature: Master-detail Related to the data grid Master-detail feature and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels May 14, 2024
@sanlee13
Copy link
Author

sanlee13 commented May 14, 2024

Hey @michelengelen,
So, when I expand the row, I have button that toggles a custom state that resides in the context data store. When I click the edit, I want to disable the row toggle (expand/collapse).

Here is a sandbox I made: https://codesandbox.io/p/sandbox/quirky-ptolemy-hdlrzd?file=%2Fsrc%2FDemo.js%3A25%2C5

EDIT: Keep an eye on the console

@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 May 14, 2024
@michelengelen
Copy link
Member

Hey @sanlee13
Is this what you are trying to achieve?

DEMO

This is making use of the row model and the apiRef.

@michelengelen michelengelen 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 May 14, 2024
@sanlee13
Copy link
Author

Hey @michelengelen,
Yes, this is precisely what I'm aiming to achieve. Your approach is fascinating and something I wouldn't have considered on my own.

Thank you very much for your assistance.

@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 May 14, 2024
@michelengelen
Copy link
Member

Great that this solution works for you.

@cherniavskii should we maybe add this as a recipe to the docs?

@cherniavskii
Copy link
Member

@michelengelen I don't love the idea of mutating row data to reflect the editing state TBH.
Forking GridDetailPanelToggleCell isn't perfect either.
I forked your demo and made 2 changes:

  • used React context for editing state
  • reused GridDetailPanelToggleCell component

https://codesandbox.io/p/sandbox/silent-frog-tqp59h

What do you think?

@michelengelen
Copy link
Member

Yes, that's a great solution.
I was thinking of using state or context at first as well, but honestly don't know why i diverted from that. Probably because using state would potentialy lead to unnecessary rerenders 🤷🏼

Thanks for providing that solution ... the question still stands though: should we add something like this as a recipe?

@cherniavskii
Copy link
Member

the question still stands though: should we add something like this as a recipe?

It seems to be a quite niche use case, I would wait for upvotes on this first.

@michelengelen michelengelen added waiting for 👍 Waiting for upvotes recipe and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customization: extend Logic customizability feature: Master-detail Related to the data grid Master-detail feature recipe support: commercial Support request from paid users support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/ waiting for 👍 Waiting for upvotes
Projects
None yet
Development

No branches or pull requests

3 participants