-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Steps to reproduce
Description
After upgrading from DataGrid v7 to v8, we're experiencing an issue with server-side rendering in tree view mode. When expanding a parent row to fetch its children, DataGrid v8 incorrectly sets rowCount to -1 if the server response doesn't include a total row count.
In v7, the DataGrid correctly maintained the existing row count when fetching child rows. However, in v8, it seems to reset the row count to -1 when loading children, causing pagination issues.
Steps to Reproduce
- Set up a DataGrid with server-side pagination and tree data, the datsource would be something like below:
const dataSource = useMemo(
() => ({
getRows: async (params: GridGetRowsParams) => {
try {
const fetchedRows = await processDataService.fetchProcessNodes(params);
return {
rows: fetchedRows.rows,
rowCount: fetchedRows.rowCount ?? 0,
};
} catch (error) {
console.error('Error fetching rows:', error);
return { rows: [], rowCount: 0 };
}
},
getGroupKey: (row: GridValidRowModel) => String(row.id),
getChildrenCount: (row: GridValidRowModel) => (row as Process).descendantCount || 0,
}),
[reloadTrigger],
);- Load initial data (e.g., 15 parent rows, which is less than our default page size of 25) with a total row count included in the response.
- Expand a parent row to fetch its children.
- In the server response for children, don't include a total row count (since we're only fetching children, not changing the total parent count).
Current behavior
- When fetching children, DataGrid logs:
MUI X: useGridRowCount - Setting 'rowCount' to -1- This causes pagination issues as the grid thinks there are no rows.
gridPageCountSelectorreturns an incorrect page count (2 in our case - got this value fromconst pageCount = useGridSelector(apiRef, gridPageCountSelector);)
Expected behavior
- DataGrid should maintain the previously known row count (15 in our case) when fetching children.
- Only update row count when fetching top-level rows or when explicitly provided.
Context
We're using DataGrid with server-side pagination and tree data. Our goal is to hide pagination when the total number of rows fits within a single page (totalRows ≤ pageSize or pageCount ≤ 1).
This worked correctly in v7, but after upgrading to v8, we're experiencing an issue where expanding a parent row to fetch its children causes DataGrid to incorrectly set rowCount to -1, which then causes pagination to appear when it shouldn't.
Additional Context
In our logs, we can see:
- When loading initial data:
MUI X: useGridRowCount - Setting 'rowCount' to 15- When fetching children (even though we do not explicitly return the rowCount):
MUI X: useGridRowCount - Setting 'rowCount' to -1This appears to be a regression from v7, where the DataGrid correctly handled this scenario.
Workaround
Currently, we're forced to return the total row count with every request, including child row requests, even though this information is redundant for child fetching operations.
Your environment
"@mui/material": "7.0.2",
"@mui/x-data-grid-premium": "8.1.0",Browser: tested in Chrome & Brave Browser
Search keywords: bug, regression, DataGrid, server-side pagination, tree data, rowCount, v8, Pagination, Custom pagintaion