Skip to content

Commit

Permalink
Change the way current row count is retrieved to support controlled r…
Browse files Browse the repository at this point in the history
…ow count updates. Handle switch from infinite to lazy loading
  • Loading branch information
arminmeh committed Sep 19, 2024
1 parent ee519a3 commit eae88f2
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@ export const useGridDataSourceLazyLoader = (
const rootGroupChildren = [...rootGroup.children];

const pageRowCount = privateApiRef.current.state.pagination.rowCount;
const rowCount = privateApiRef.current.getRowsCount();
const rootChildrenCount = rootGroupChildren.length;

if (pageRowCount === undefined || rowCount >= pageRowCount) {
if (
pageRowCount === undefined ||
rootChildrenCount === 0 ||
rootChildrenCount >= pageRowCount
) {
return;
}

for (let i = 0; i < pageRowCount - rowCount; i += 1) {
for (let i = 0; i < pageRowCount - rootChildrenCount; i += 1) {
const skeletonId = getSkeletonRowId(i);

rootGroupChildren.push(skeletonId);
Expand Down Expand Up @@ -286,6 +290,7 @@ export const useGridDataSourceLazyLoader = (
);

useGridApiEventHandler(privateApiRef, 'rowsFetched', handleDataUpdate);
useGridApiEventHandler(privateApiRef, 'rowCountChange', handleDataUpdate);
useGridApiEventHandler(privateApiRef, 'scrollPositionChange', handleScrolling);
useGridApiEventHandler(
privateApiRef,
Expand Down

0 comments on commit eae88f2

Please sign in to comment.