[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.
-
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
treeData
on 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
,updateRows
and even updaterows
prop 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:hasChildrenOnServer
returnsfalse
for this row), this one will keep working as current.hasChildrenOnServer
returnstrue
and we could do one of the following:rowTreeCreation
to this row for it to be declared asrowNode.type === group
, on fetching the data we can_delete
this 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.type
isleaf
, on fetching the new rows therowNode.type
of this row will be recomputed to begroup
as it has now some children represented by path provided bygetTreeDataPath
rows
prop but more could be loaded lazily ashasChildrenOnServer
returnstrue
for this row.defaultGroupingExpansionDepth
orisGroupExpandedByDefault
, 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.updateRows
on 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.updateRows
instead 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