Closed agirgol closed 3 months ago
@agirgol We currently have no way of controlling the open/closed state of tree data.
The code you provided looks ok, but could you please try to replicate this in a codesandbox with a dummy server? It would really help to see it in action.
Ah, now I get it.
So the problem is that you are controlling the selectedRowIds
. The state update will trigger a rerender and since we have no controlled state for the opened/closed grouped rows in the tree data it will default to the initial state.
Not sure id we can do something about that atm.
@MBilalShafi do you have any idea if we can provide a workaround for that?
@agirgol
Move the getTreeDataPath
definition outside of the component so it has stable reference:
+const getTreeDataPath: DataGridProProps<"getTreeDataPath"> = (row) => row.path.split("/");
<DataGridPro
- getTreeDataPath={(row) => row.path.split("/")}
+ getTreeDataPath={getTreeDataPath}
Or wrap it with useCallback
:
+const getTreeDataPath = React.useCallback<
+ DataGridProProps<"getTreeDataPath">
+>((row) => row.path.split("/"), []);
<DataGridPro
- getTreeDataPath={(row) => row.path.split("/")}
+ getTreeDataPath={getTreeDataPath}
+
Working demo: https://codesandbox.io/p/sandbox/treedata-forked-tq5xhd?file=%2Fsrc%2Fcomponents%2FTreeDataGrid.tsx%3A121%2C5
Thank you very much for your support. Your suggestions worked.
:warning: 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.
@agirgol: 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.
@agirgol I've added a warning to the Tree Data docs in https://github.com/mui/mui-x/pull/13519, thanks for your feedback!
Since my data template is not the same template, I used useCallback by changing it according to the data as follows. https://codesandbox.io/p/sandbox/treedata-h9zn94
const getTreeDataPath: DataGridProProps['getTreeDataPath'] = React.useCallback(
(row: any) => {
const pathArray = row.path.split("/");
return pathArray;
},
[]
);
I am using treedata in the DataGridPro table and keeping the row ids to perform operations based on the selected rows. But when retrieving the ids, the table nodes are closed. In other words, the nodes close in every line I select. What method should I follow so that the nodes do not close and remain as they are?