mui / mui-x

MUI X: Build complex and data-rich applications using a growing list of advanced React components, like the Data Grid, Date and Time Pickers, Charts, and more!
https://mui.com/x/
4.51k stars 1.31k forks source link

[question] Tree Data: How to switch between tree data and ordinary grid without tree data #10251

Open Ol-Boiko opened 1 year ago

Ol-Boiko commented 1 year ago

Order ID or Support key 💳 (optional)

-

Duplicates

Latest version

The problem in depth 🔍

I want to have possibility to switch between ordinary grid and grid with Tree data like in this example: https://codesandbox.io/s/data-grid-community-forked-yqx6v2?file=/src/App.tsx

if i click to the button "switch Tree"- i'll receive an error "MUI: No getTreeDataPath given."

Thanks in advance

Your environment 🌎

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

Interesting... that's probably a bug. But you can easily solve it by always passing the getTreeDataPath, it will just be ignored when treeData === false.

And by the way, you should always memoize getTreeDataPath to avoid re-generating the tree on every render.

Ol-Boiko commented 1 year ago

Hi flaviendelangle! Thanks for replying! Yeah, agree about memoizing but it was just for simplifying code for an example. I have my getTreeDataPath outside the component. If it is a bug, I hope this will be fixed soon. We need this functionality so much. For now if I switch from Tree Data to simple Grid I'm hiding Group column and disable it in manage column menu, creating fake path for rows, but it takes much efforts for development and automation teams to support all this logic since functionality of Data Grid is overcomplicated and without it

flaviendelangle commented 1 year ago

Is there something preventing you from just always passing getTreeDataPath to your grid?

Ol-Boiko commented 1 year ago

Previously I received an error when I tried to do in the project. But I used your suggestion and look at it in the different perspective. I cleaned up all the rows while clicking before changing treeData to true and then generated new rows with path and it worked! no Group column in grid and no error!!! https://codesandbox.io/s/data-grid-community-forked-vyktlt?file=/src/App.tsx Thanks a lot!

flaviendelangle commented 1 year ago

No problem, we'll keep this issue open to find a proper fix :+1: