You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[EuiDataGrid] Identifying when the user has scrolled to the bottom. #8422
The EuiDataGrid is one of the Primary components for the Discover Page in Kibana.
We are changing the pagination behaviour and introducing features like Load More and Infinite Scrolling. For both of these use cases, we need to somehow capture when the user has scrolled to the bottom.
Options explored
The underlying react-window offers couple of virtualisation options with which this could have been achieved.
onItemsRendered - This function spits out the last visible row number on the current screen. Meaning we tried checking for total number rows expected against current visible last row to figure out if the user has reached the bottom of the page or not. Thought this seemed ideal, it had its own shortcoming. It introduced a small flicker situation right at the point where we decided to toggle the behaviour based on if the user has reached the bottom of the page or not. Demo here .
onScroll - This seems to be our escape hatch. That whenever the user starts scrolling, we capture the outerRef from the DOM and manually compute the scroll position. This seemed to work nicely for us.
Though one challenge we see is we had to grab the outerRef manually from the DOM and that react-window does expose it, EUI restricts access to the ref.
For some added context, the flickering was caused because toggling the footer changes the height of the scrollable area, which can also change the last visible row. It then got stuck in a loop of showing and hiding the footer each frame as the last visible row changed.
Using onScroll we can check the scroll height of the scrollable area (by manually querying the DOM) and toggle the footer within a certain margin from the bottom. We can also account for the footer height when it's visible in the check, avoiding the flickering issue. The main problem is that we don't have access to outerRef through EuiDataGrid, so it would be great if that could be exposed by EUI (or an alternative way to do this).
💭 While exposing the outerRef is more powerful it also leaks more internal implementation details. A viable alternative could be to enrich the arguments passed to the onScroll callback to include more geometry information so the event handler doesn't need to access DOM information on the side to perform its function.
I analyzed the Kibana use case: src/platform/packages/shared/kbn-unified-data-table/src/components/data_table.tsx
The implementation:
uses the outerRef (react-window wrapper), manually queried because it isn't exposed by EUI in virtualizationOptions, to calculate if the bottom has been reached,
needs hasScrolledToBottom information to display a load more button if content is paginated and there is more data to load.
We are passing the virtualizationOptions as they are to the VariableSizeGrid imported from react-window. Here's the definition of onScroll. It passes: horizontalScrollDirection, scrollLeft, scrollTop, scrollUpdateWasRequested, verticalScrollDirection.
What we can do is in packages/eui/src/components/datagrid/body/data_grid_body_virtualized.tsx get the onScroll passed by the consumer in virtualizationOptions and enrich it with the scrollHeight, offsetHeight from outerGridRef, or even, a boolean flag hasScrolledToBottom to avoid consumers having to calculate it themselves (example).
@weronikaolejniczak Thanks for looking into it, and that sounds great. We may still need the values specifically to continue accounting for the footer height, but passing them through onScroll sounds like it would work well.
This should be low effort, we're treating this as a high priority and pulling it to the top of our backlog. Note to remember to update our docs as part of this fix 👍 .
Activity
davismcphee commentedon Mar 11, 2025
For some added context, the flickering was caused because toggling the footer changes the height of the scrollable area, which can also change the last visible row. It then got stuck in a loop of showing and hiding the footer each frame as the last visible row changed.
Using
onScrollwe can check the scroll height of the scrollable area (by manually querying the DOM) and toggle the footer within a certain margin from the bottom. We can also account for the footer height when it's visible in the check, avoiding the flickering issue. The main problem is that we don't have access toouterRefthroughEuiDataGrid, so it would be great if that could be exposed by EUI (or an alternative way to do this).weltenwort commentedon Mar 12, 2025
💭 While exposing the
outerRefis more powerful it also leaks more internal implementation details. A viable alternative could be to enrich the arguments passed to theonScrollcallback to include more geometry information so the event handler doesn't need to access DOM information on the side to perform its function.weronikaolejniczak commentedon Mar 18, 2025
I analyzed the Kibana use case:
src/platform/packages/shared/kbn-unified-data-table/src/components/data_table.tsxThe implementation:
outerRef(react-windowwrapper), manually queried because it isn't exposed by EUI invirtualizationOptions, to calculate if the bottom has been reached,hasScrolledToBottominformation to display a load more button if content is paginated and there is more data to load.We are passing the
virtualizationOptionsas they are to theVariableSizeGridimported from react-window. Here's the definition ofonScroll. It passes:horizontalScrollDirection,scrollLeft,scrollTop,scrollUpdateWasRequested,verticalScrollDirection.What we can do is in
packages/eui/src/components/datagrid/body/data_grid_body_virtualized.tsxget theonScrollpassed by the consumer invirtualizationOptionsand enrich it with thescrollHeight,offsetHeightfromouterGridRef, or even, a boolean flaghasScrolledToBottomto avoid consumers having to calculate it themselves (example).davismcphee commentedon Mar 18, 2025
@weronikaolejniczak Thanks for looking into it, and that sounds great. We may still need the values specifically to continue accounting for the footer height, but passing them through
onScrollsounds like it would work well.JasonStoltz commentedon Mar 20, 2025
This should be low effort, we're treating this as a high priority and pulling it to the top of our backlog. Note to remember to update our docs as part of this fix 👍 .