|
289 | 289 | }
|
290 | 290 |
|
291 | 291 | 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 | + } |
303 | 314 | }
|
304 | 315 | }
|
305 | 316 | }
|
|
0 commit comments