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

[docs][data grid] Warn about getTreeDataPath reference #13519

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/data/data-grid/export/ExcelCustomExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,14 @@ const exceljsPostProcess = ({ worksheet }) => {

const excelOptions = { exceljsPreProcess, exceljsPostProcess };

const getTreeDataPath = (row) => row.path;

export default function ExcelCustomExport() {
return (
<div style={{ height: 500, width: '100%' }}>
<DataGridPremium
treeData
getTreeDataPath={(row) => row.path}
getTreeDataPath={getTreeDataPath}
rows={rows}
columns={columns}
groupingColDef={groupingColDef}
Expand Down
5 changes: 4 additions & 1 deletion docs/data/data-grid/export/ExcelCustomExport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
GridToolbar,
GridExceljsProcessInput,
GridColDef,
DataGridPremiumProps,
} from '@mui/x-data-grid-premium';

const rows = [
Expand Down Expand Up @@ -279,12 +280,14 @@ const exceljsPostProcess = ({ worksheet }: GridExceljsProcessInput) => {

const excelOptions = { exceljsPreProcess, exceljsPostProcess };

const getTreeDataPath: DataGridPremiumProps['getTreeDataPath'] = (row) => row.path;

export default function ExcelCustomExport() {
return (
<div style={{ height: 500, width: '100%' }}>
<DataGridPremium
treeData
getTreeDataPath={(row) => row.path}
getTreeDataPath={getTreeDataPath}
rows={rows}
columns={columns}
groupingColDef={groupingColDef}
Expand Down
2 changes: 1 addition & 1 deletion docs/data/data-grid/export/ExcelCustomExport.tsx.preview
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<DataGridPremium
treeData
getTreeDataPath={(row) => row.path}
getTreeDataPath={getTreeDataPath}
rows={rows}
columns={columns}
groupingColDef={groupingColDef}
Expand Down
14 changes: 12 additions & 2 deletions docs/data/data-grid/tree-data/tree-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ const rows: GridRowsProp = [
{ path: ['Sarah', 'Thomas', 'Karen'], jobTitle: 'Sales Person', id: 3 },
];

const getTreeDataPath: DataGridProProps['getTreeDataPath'] = (row) => row.path;

<DataGridPro
treeData
getTreeDataPath={(row) => row.path}
getTreeDataPath={getTreeDataPath}
rows={rows}
columns={columns}
/>;
Expand All @@ -41,14 +43,22 @@ const rows: GridRowsProp = [
{ path: 'Sarah/Thomas/Karen', jobTitle: 'Sales Person', id: 3 },
];

const getTreeDataPath: DataGridProProps['getTreeDataPath'] = (row) =>
row.path.split('/');

<DataGridPro
treeData
getTreeDataPath={(row) => row.path.split('/')}
getTreeDataPath={getTreeDataPath}
rows={rows}
columns={columns}
/>;
```

:::warning
The `getTreeDataPath` prop should keep the same reference between two renders.
If it changes, the data grid will consider that the data has changed and will recompute the tree resulting in collapsing all the rows.
:::

{{"demo": "TreeDataSimple.js", "bg": "inline", "defaultCodeOpen": false}}

## Custom grouping column
Expand Down
Loading