Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions src/features/infinite-scroll/js/infinite-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,17 +289,28 @@
}

if (args.y) {
var percentage;
var targetPercentage = args.grid.options.infiniteScrollRowsFromEnd / args.grid.renderContainers.body.visibleRowCache.length;
if (args.grid.scrollDirection === uiGridConstants.scrollDirection.UP ) {
percentage = args.y.percentage;
if (percentage <= targetPercentage){
service.loadData(args.grid);
}
} else if (args.grid.scrollDirection === uiGridConstants.scrollDirection.DOWN) {
percentage = 1 - args.y.percentage;
if (percentage <= targetPercentage){
service.loadData(args.grid);

// If the user is scrolling very quickly all the way to the top/bottom, the scroll handler can get confused
// about the direction. First we check if they've gone all the way, and data always is loaded in this case.
if (args.y.percentage === 0) {
args.grid.scrollDirection = uiGridConstants.scrollDirection.UP;
service.loadData(args.grid);
} else if (args.y.percentage === 1) {
args.grid.scrollDirection = uiGridConstants.scrollDirection.DOWN;
service.loadData(args.grid);
} else { // Scroll position is somewhere in between top/bottom, so determine whether it's far enough to load more data.
var percentage;
var targetPercentage = args.grid.options.infiniteScrollRowsFromEnd / args.grid.renderContainers.body.visibleRowCache.length;
if (args.grid.scrollDirection === uiGridConstants.scrollDirection.UP ) {
percentage = args.y.percentage;
if (percentage <= targetPercentage){
service.loadData(args.grid);
}
} else if (args.grid.scrollDirection === uiGridConstants.scrollDirection.DOWN) {
percentage = 1 - args.y.percentage;
if (percentage <= targetPercentage){
service.loadData(args.grid);
}
}
}
}
Expand Down