ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

Infinite scroll does not fire needLoadMoreData when bottom of table is reached on iOS

Open Grigorius opened this issue 11 years ago • 4 comments

If the user scrolls towards the bottom of the table (into the infiniteScrollRowsFromEnd: XY teritory), but does not reach the bottom of the table - then needLoadMoreData fires. If the user scrolls towards the bottom and reaches the last element then needLoadMoreData does NOT fire.

This can be tested here: http://ui-grid.info/docs/#/tutorial/212_infinite_scroll on an iPhone (scroll to the bottom - no event, stop a bit before and the event fires).

Upon inspecting handleScroll - I see that args.grid.scrollDirection is up instead of down (probably because of bounce effect?)

DIRTY FIX: (in handlescroll function check if percentage is 1 (we are at the bottom - however scroll direction is somehow - up -> threat this as an iOS quirck)

if (args.grid.scrollDirection === uiGridConstants.scrollDirection.UP ) {
            percentage = args.y.percentage;
            if (percentage <= targetPercentage){
              service.loadData(args.grid);
            }
            //ios bugfix
            if (percentage == 1) {
                args.grid.scrollDirection = "down";
                service.loadData(args.grid);
            }
          }

Grigorius avatar Aug 12 '15 16:08 Grigorius

I was able to confirm this bug in my work app - what is happening here is that scrollTop in this line is returning a smaller value by 1px than the previous value when one scrolls with momentum scrolling (i.e. -webkit-overflow-scrolling: touch) to the end of the grid.

A hack that can be done to fix buggy Safari behavior is to adjust the check in https://github.com/angular-ui/ui-grid/blob/master/src/js/core/factories/GridRenderContainer.js#L348 to perhaps allow a buffer of 2px (add + 1 to the yDiff and allow yDiff >= 0) - one should not be able to scroll with a 0px change, so this is ok IMO.

wesleycho avatar Oct 26 '15 18:10 wesleycho

I can reproduce this behavior on a desktop by scrolling to the bottom of the grid and then scrolling UP before needLoadMoreData is called. Hitting breakpoints inside ui-grid.js:loadData, grid.scrollDirection is set to "up" even though it was a down scroll that triggered the load.

I got around this by declaring a dummy function to needMoreDataTop: this.gridApi.infiniteScroll.on.needLoadMoreDataTop(this.$scope, () => { this.gridApi.infiniteScroll.dataLoaded(); } );

Now that infiniteScroll.dataLoaded() is getting called, infinite scroll is getting triggered properly. I could not disable infinite scrolling up, even though documentation says I can use gridOptions.infiniteScrollUp = false, when in the LoadData function it was checking grid.infiniteScroll.scrollUp which was always set to true.

AThomsonTrimble avatar Jul 10 '17 19:07 AThomsonTrimble

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 23 '18 05:05 stale[bot]

This issue has been automatically closed because it has not had recent activity. If you believe that this is still an issue in the latest version, feel free to re-open it. Thank you for your contributions.

stale[bot] avatar Jun 22 '18 06:06 stale[bot]