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

[DataGrid] Fix rows not being recomputed on props.rowCount change #12833

Merged
merged 1 commit into from
May 2, 2024
Merged
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
12 changes: 10 additions & 2 deletions packages/x-data-grid/src/hooks/features/rows/useGridRows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const useGridRows = (
const currentPage = useGridVisibleRows(apiRef, props);

const lastUpdateMs = React.useRef(Date.now());
const lastRowCount = React.useRef(props.rowCount);
const timeout = useTimeout();

const getRow = React.useCallback<GridRowApi['getRow']>(
Expand Down Expand Up @@ -594,6 +595,12 @@ export const useGridRows = (
return;
}

let isRowCountPropUpdated = false;
if (props.rowCount !== lastRowCount.current) {
isRowCountPropUpdated = true;
lastRowCount.current = props.rowCount;
}

const areNewRowsAlreadyInState =
apiRef.current.caches.rows.rowsBeforePartialUpdates === props.rows;
const isNewLoadingAlreadyInState =
Expand Down Expand Up @@ -625,8 +632,9 @@ export const useGridRows = (
apiRef.current.caches.rows.rowCountPropBeforePartialUpdates = props.rowCount;
apiRef.current.forceUpdate();
}

return;
if (!isRowCountPropUpdated) {
return;
}
}

logger.debug(`Updating all rows, new length ${props.rows.length}`);
Expand Down
Loading