Skip to content

Commit 87c9eed

Browse files
Portugal, Marcelomportuga
Portugal, Marcelo
authored andcommitted
fix(Grid.js): scrollToIfNecessary can scroll to last row.
Updated the scrollToIfNecessary to treat any percentage number for the scroll position that is greater than 1 as 1. fix #6571, fix #6507, fix #6563
1 parent 842a9b7 commit 87c9eed

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

misc/tutorial/202_cellnav.ngdoc

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ For better performance with the following example, you can choose to load the ui
125125
<button type="button" class="btn btn-success" ng-click="$ctrl.scrollTo(20,0)">Scroll To Row 20</button>
126126
<button type="button" class="btn btn-success" ng-click="$ctrl.scrollTo(0,7)">Scroll To Balance</button>
127127
<button type="button" class="btn btn-success" ng-click="$ctrl.scrollTo(50,7)">Scroll To Row 50, Balance</button>
128+
<button type="button" class="btn btn-success" ng-click="$ctrl.scrollTo(499,7)">Scroll To Row 499, Balance</button>
128129
<button type="button" class="btn btn-success" ng-click="$ctrl.scrollToFocus(50,7)">Focus Row 50, Balance</button>
129130
<br>
130131
<br>

src/js/core/factories/Grid.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -2339,6 +2339,14 @@ angular.module('ui.grid')
23392339
return this.hasRightContainer() && this.renderContainers.right.renderedColumns.length > 0;
23402340
};
23412341

2342+
// Turn the scroll position into a percentage and make it an argument for a scroll event
2343+
function getScrollPercentage(scrollPixels, scrollLength) {
2344+
var percentage = scrollPixels / scrollLength;
2345+
2346+
// if the percentage is greater than 1, set it to 1
2347+
return percentage <= 1 ? percentage : 1;
2348+
}
2349+
23422350
/**
23432351
* @ngdoc method
23442352
* @methodOf ui.grid.class:Grid
@@ -2405,31 +2413,23 @@ angular.module('ui.grid')
24052413
// Don't let the pixels required to see the row be less than zero
24062414
pixelsToSeeRow = (pixelsToSeeRow < 0) ? 0 : pixelsToSeeRow;
24072415

2408-
var scrollPixels, percentage;
2416+
var scrollPixels;
24092417

24102418
// If the scroll position we need to see the row is LESS than the top boundary, i.e. obscured above the top of the self...
24112419
if (pixelsToSeeRow < topBound) {
24122420
// Get the different between the top boundary and the required scroll position and subtract it from the current scroll position\
24132421
// to get the full position we need
24142422
scrollPixels = self.renderContainers.body.prevScrollTop - (topBound - pixelsToSeeRow);
24152423

2416-
// Turn the scroll position into a percentage and make it an argument for a scroll event
2417-
percentage = scrollPixels / scrollLength;
2418-
if (percentage <= 1) {
2419-
scrollEvent.y = { percentage: percentage };
2420-
}
2424+
scrollEvent.y = { percentage: getScrollPercentage(scrollPixels, scrollLength) };
24212425
}
24222426
// Otherwise if the scroll position we need to see the row is MORE than the bottom boundary, i.e. obscured below the bottom of the self...
24232427
else if (pixelsToSeeRow > bottomBound) {
24242428
// Get the different between the bottom boundary and the required scroll position and add it to the current scroll position
24252429
// to get the full position we need
24262430
scrollPixels = pixelsToSeeRow - bottomBound + self.renderContainers.body.prevScrollTop;
24272431

2428-
// Turn the scroll position into a percentage and make it an argument for a scroll event
2429-
percentage = scrollPixels / scrollLength;
2430-
if (percentage <= 1) {
2431-
scrollEvent.y = { percentage: percentage };
2432-
}
2432+
scrollEvent.y = { percentage: getScrollPercentage(scrollPixels, scrollLength) };
24332433
}
24342434
}
24352435

0 commit comments

Comments
 (0)