Skip to content

Commit

Permalink
rework how scrolling works after filtring or sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
DanailH committed Aug 25, 2022
1 parent 79eb868 commit 88ea46f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,33 +134,36 @@ export const useGridLazyLoader = (
return;
}

const fetchRowsParams: GridFetchRowsParams = {
firstRowToRender: params.firstRowToRender,
lastRowToRender: params.lastRowToRender,
sortModel,
filterModel,
};

if (
renderedRowsIntervalCache.current.firstRowToRender === params.firstRowToRender &&
renderedRowsIntervalCache.current.lastRowToRender === params.lastRowToRender &&
sortModel.length === 0 &&
filterModel.items.length === 0
renderedRowsIntervalCache.current.lastRowToRender === params.lastRowToRender
) {
return;
}

const skeletonRowsSection = findSkeletonRowsSection(visibleRows.rows, {
firstRowIndex: params.firstRowToRender,
lastRowIndex: params.lastRowToRender,
});
if (sortModel.length === 0 && filterModel.items.length === 0) {
const skeletonRowsSection = findSkeletonRowsSection(visibleRows.rows, {
firstRowIndex: params.firstRowToRender,
lastRowIndex: params.lastRowToRender,
});

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

fetchRowsParams.firstRowToRender = skeletonRowsSection.firstRowIndex;
fetchRowsParams.lastRowToRender = skeletonRowsSection.lastRowIndex;
}

renderedRowsIntervalCache.current = params;

const fetchRowsParams: GridFetchRowsParams = {
firstRowToRender: skeletonRowsSection.firstRowIndex,
lastRowToRender: skeletonRowsSection.lastRowIndex,
sortModel,
filterModel,
};

apiRef.current.publishEvent('fetchRows', fetchRowsParams);
},
[apiRef, props.rowsLoadingMode, sortModel, filterModel, visibleRows.rows, lazyLoading],
Expand All @@ -169,7 +172,6 @@ export const useGridLazyLoader = (
const handleGridSortModelChange = React.useCallback<GridEventListener<'sortModelChange'>>(
(newSortModel) => {
const dimensions = apiRef.current.getRootDimensions();

if (
isLazyLoadingDisabled({
lazyLoadingFeatureFlag: lazyLoading,
Expand All @@ -180,6 +182,8 @@ export const useGridLazyLoader = (
return;
}

apiRef.current.unstable_requestPipeProcessorsApplication('hydrateRows');

const { firstRowToRender, lastRowToRender } = getCurrentIntervalToRender();
const fetchRowsParams: GridFetchRowsParams = {
firstRowToRender,
Expand Down Expand Up @@ -207,6 +211,8 @@ export const useGridLazyLoader = (
return;
}

apiRef.current.unstable_requestPipeProcessorsApplication('hydrateRows');

const { firstRowToRender, lastRowToRender } = getCurrentIntervalToRender();
const fetchRowsParams: GridFetchRowsParams = {
firstRowToRender,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ describe('<DataGridPro /> - Lazy loader', () => {
render(<TestLazyLoader onFetchRows={handleFetchRows} rowCount={50} />);

expect(handleFetchRows.callCount).to.equal(1);
// Should be 2. When tested in the browser it's called only 2 time
// Should be 1. When tested in the browser it's called only 2 time
fireEvent.click(getColumnHeaderCell(0));
expect(handleFetchRows.callCount).to.equal(3);
expect(handleFetchRows.callCount).to.equal(2);
});

it('should render skeleton cell if rowCount is bigger than the number of rows', function test() {
Expand Down

0 comments on commit 88ea46f

Please sign in to comment.