[RFC][Tree data] Lazy-load row children properties #9114
Replies: 1 comment 5 replies
-
This is a good start! But what if instead of building this into the data grid, we fix the tree data lazy loading example and extract the custom code into a hook? import { DataGridPro, useGridApiRef, useTreeDataLazyLoading } from '@mui/x-data-grid-pro';
function Demo() {
const apiRef = useGridApiRef();
const [rows] = React.useState([]);
const { groupingColDef } = useTreeDataLazyLoading({
apiRef,
getRows: async (treeDataPath) => {
const data = await fetchData(treeDataPath);
return data;
},
});
return (
<DataGrid
treeData
apiRef={apiRef}
rows={rows}
columns={columns}
getTreeDataPath={getTreeDataPath}
groupingColDef={groupingColDef}
/>
)
}I created a sandbox where I tried to implement it: https://codesandbox.io/s/beautiful-goldberg-6rm4rm?file=/demo.tsx This could be a temporary solution without virtually no internal changes to the data grid. The client-side features will work with it. What do you think? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This discussion discusses briefly the trade-offs and approaches under consideration for the implementation of properties for lazy load row children i.e #3377
Approach:
The idea is to make it work in the hybrid mode, i.e. users can provide initial
treeDataon the client side and they can provide two extra props using which they can lazy-load row children for certain rows, but they can still use methods likesetRows,updateRowsand even updaterowsprop on the client side, here are the two extra props as suggested in the original ticket:Now, for parent rows (mostly those with
rowNode.type === 'group') there could be these possibilities:hasChildrenOnServerreturnsfalsefor this row), this one will keep working as current.hasChildrenOnServerreturnstrueand we could do one of the following:rowTreeCreationto this row for it to be declared asrowNode.type === group, on fetching the data we can_deletethis row and replace with the fetched rows.rowNode(like a booleanrowNode.serverSideData) which will be used to show expand icon in the row although its currentrowNode.typeisleaf, on fetching the new rows therowNode.typeof this row will be recomputed to begroupas it has now some children represented by path provided bygetTreeDataPathrowsprop but more could be loaded lazily ashasChildrenOnServerreturnstruefor this row.defaultGroupingExpansionDepthorisGroupExpandedByDefault, same applies to server-side only rows)As this is not the final solution, a full fledge solution would require to have a data fetching layer like AGGrid has (context) and then we can define it something like
treeDataMode="server"to fully make it server side.Impact on Data Processors like Filtering, Sorting, etc
As this one is a quick solution that unlocks people to achieve something closer to the full fledge solution, I wanted to have all the other features like filtering, sorting, aggregation, etc work in the same way as on the client side, it's the same as if a user is doing
apiRef.current.updateRowson the client side. It's more relatable as underlying, this approach will use the same partial row update API (apiRef.current.updateRows)For example, on this demo filtering on client-side persists on adding new rows using (
apiRef.current.updateRows)Users can move filtering, sorting, etc to the server-side using
filteringMode='server'for example, but it may not work ideally as we are only updating part of rows usingapiRef.current.updateRowsinstead of updating all the rows for performance reasons.Pros:
Cons:
Conclusion
The purpose of RFC is to bring everyone on the same page before the actual implementation. Any comments or feedback would be appreciated.
Beta Was this translation helpful? Give feedback.
All reactions