Skip to content

[data grid] rowCount set to -1 when fetching child rows in server-side Tree Data #17626

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

Open
mannam95 opened this issue Apr 30, 2025 · 1 comment · May be fixed by #17711
Open

[data grid] rowCount set to -1 when fetching child rows in server-side Tree Data #17626

mannam95 opened this issue Apr 30, 2025 · 1 comment · May be fixed by #17711
Assignees
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! feature: Server integration Better integration with backends, e.g. data source feature: Tree data Related to the data grid Tree data feature

Comments

@mannam95
Copy link

mannam95 commented Apr 30, 2025

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

  1. 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],
  );
  1. 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.
  2. Expand a parent row to fetch its children.
  3. 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.
  • gridPageCountSelector returns an incorrect page count (2 in our case - got this value from const 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 -1

This 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

@mannam95 mannam95 added bug 🐛 Something doesn't work status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Apr 30, 2025
@github-actions github-actions bot added the component: data grid This is the name of the generic UI component, not the React module! label Apr 30, 2025
@oliviertassinari oliviertassinari changed the title [Bug] DataGrid v8 sets rowCount to -1 when fetching child rows in server-side Datagrid-tree-data [data grid] DataGrid v8 sets rowCount to -1 when fetching child rows in server-side Datagrid-tree-data May 4, 2025
@arminmeh arminmeh self-assigned this May 6, 2025
@arminmeh arminmeh changed the title [data grid] DataGrid v8 sets rowCount to -1 when fetching child rows in server-side Datagrid-tree-data [data grid] rowCount set to -1 when fetching child rows in server-side Tree Data May 6, 2025
@arminmeh arminmeh added feature: Tree data Related to the data grid Tree data feature feature: Server integration Better integration with backends, e.g. data source and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels May 6, 2025
@arminmeh
Copy link
Contributor

arminmeh commented May 6, 2025

In v7, rowCount was ignored if undefined, while in v8 it is set to -1
I think that we can ignore it altogether, since it does not make sense to update root row count while loading children.

I will open a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! feature: Server integration Better integration with backends, e.g. data source feature: Tree data Related to the data grid Tree data feature
Projects
None yet
2 participants