diff --git a/packages/x-data-grid-pro/src/tests/infiniteLoader.DataGridPro.test.tsx b/packages/x-data-grid-pro/src/tests/infiniteLoader.DataGridPro.test.tsx index 3c941053e0f1..b21bc104604b 100644 --- a/packages/x-data-grid-pro/src/tests/infiniteLoader.DataGridPro.test.tsx +++ b/packages/x-data-grid-pro/src/tests/infiniteLoader.DataGridPro.test.tsx @@ -160,4 +160,52 @@ describe(' - Infnite loader', () => { // should not load more rows because the threshold is not reached expect(getRow.callCount).to.equal(5); }); + + it('should not call `onRowsScrollEnd` if there are rows pinned to the bottom and the viewport scroll is at the top', async function test() { + if (isJSDOM) { + this.skip(); // Needs layout + } + const baseRows = [ + { id: 0, brand: 'Nike' }, + { id: 1, brand: 'Adidas' }, + { id: 2, brand: 'Puma' }, + { id: 3, brand: 'Under Armor' }, + { id: 4, brand: 'Jordan' }, + { id: 5, brand: 'Reebok' }, + ]; + const basePinnedRows = { + bottom: [{ id: 6, brand: 'Unbranded' }], + }; + + const handleRowsScrollEnd = spy(); + function TestCase({ + rows, + pinnedRows, + }: { + rows: typeof baseRows; + pinnedRows: typeof basePinnedRows; + }) { + return ( +
+ +
+ ); + } + const { container } = render(); + const virtualScroller = container.querySelector('.MuiDataGrid-virtualScroller')!; + await sleep(1); + // after initial render and a scroll event that did not reach the bottom of the grid + // the `onRowsScrollEnd` should not be called + expect(handleRowsScrollEnd.callCount).to.equal(0); + // arbitrary number to make sure that the bottom of the grid window is reached. + virtualScroller.scrollTop = 12345; + virtualScroller.dispatchEvent(new Event('scroll')); + await sleep(1); + expect(handleRowsScrollEnd.callCount).to.equal(1); + }); }); diff --git a/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx b/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx index d986452fabbc..cdb2ca3029df 100644 --- a/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx +++ b/packages/x-data-grid/src/hooks/features/virtualization/useGridVirtualScroller.tsx @@ -503,7 +503,7 @@ export const useGridVirtualScroller = () => { if (panel) { rows.push(panel); } - if (isLastVisible) { + if (params.position === undefined && isLastVisibleInSection) { rows.push(apiRef.current.getInfiniteLoadingTriggerElement?.({ lastRowId: id })); } });