Skip to content

Commit 4953622

Browse files
Leah BentleyJLLeitschuh
Leah Bentley
authored andcommitted
fix(infinitescroll): make sure more data is always loaded if scrolled to top/bottom quickly (#5183)
1 parent d6d00c2 commit 4953622

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

src/features/infinite-scroll/js/infinite-scroll.js

+22-11
Original file line numberDiff line numberDiff line change
@@ -289,17 +289,28 @@
289289
}
290290

291291
if (args.y) {
292-
var percentage;
293-
var targetPercentage = args.grid.options.infiniteScrollRowsFromEnd / args.grid.renderContainers.body.visibleRowCache.length;
294-
if (args.grid.scrollDirection === uiGridConstants.scrollDirection.UP ) {
295-
percentage = args.y.percentage;
296-
if (percentage <= targetPercentage){
297-
service.loadData(args.grid);
298-
}
299-
} else if (args.grid.scrollDirection === uiGridConstants.scrollDirection.DOWN) {
300-
percentage = 1 - args.y.percentage;
301-
if (percentage <= targetPercentage){
302-
service.loadData(args.grid);
292+
293+
// If the user is scrolling very quickly all the way to the top/bottom, the scroll handler can get confused
294+
// about the direction. First we check if they've gone all the way, and data always is loaded in this case.
295+
if (args.y.percentage === 0) {
296+
args.grid.scrollDirection = uiGridConstants.scrollDirection.UP;
297+
service.loadData(args.grid);
298+
} else if (args.y.percentage === 1) {
299+
args.grid.scrollDirection = uiGridConstants.scrollDirection.DOWN;
300+
service.loadData(args.grid);
301+
} else { // Scroll position is somewhere in between top/bottom, so determine whether it's far enough to load more data.
302+
var percentage;
303+
var targetPercentage = args.grid.options.infiniteScrollRowsFromEnd / args.grid.renderContainers.body.visibleRowCache.length;
304+
if (args.grid.scrollDirection === uiGridConstants.scrollDirection.UP ) {
305+
percentage = args.y.percentage;
306+
if (percentage <= targetPercentage){
307+
service.loadData(args.grid);
308+
}
309+
} else if (args.grid.scrollDirection === uiGridConstants.scrollDirection.DOWN) {
310+
percentage = 1 - args.y.percentage;
311+
if (percentage <= targetPercentage){
312+
service.loadData(args.grid);
313+
}
303314
}
304315
}
305316
}

0 commit comments

Comments
 (0)