[DataGridPro] feat add last row for infinite scroll rows with intersection observer element #7416
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This feature is adding an empty div with id
mui-data-grid-last-row-id
this empty div is used for proper infinite scroll purpose, we cant depend ononRowsScrollEnd
callback for infinite scroll or cursor-based pagination.Problem:
For eg. DataGridPro with height 1000px, calling backend infinite scroll with limit 2 items, hence backend returning 2 items and next cursor, the 2 items are rendered on the DataGrid however unable to scroll, as 1 row took 50px only, hence unable handle next cursor infinite scroll.
Screen.Recording.2023-01-07.at.8.23.03.PM.mov
as the video shown, the items loaded from backend but unable to scroll, hence cant fetch again for another cursor items...with the onRowsScrollEnd callback...
Solution:
Infinite scroll should be handle with IntersectionObserver native js api. With the id empty div we can observe the element in viewport and then fetch next cursor items.
Note*: the empty div with id must be always at the last items of the scroll list.
Result:
Screen.Recording.2023-01-07.at.5.20.38.PM.mp4
I think i have presented the proof of concept and the practical way of implementing the infinite scroll list or cursor based pagination. However i unable to implement it via slot hence I hope maintainer can add it as slot. The slot must always at the last item of the scroll list.