Skip to content

Commit e52aaaf

Browse files
committed
Merge pull request #5142 from korolyovvalentin/master
fix(core): Incorrect horizontal scroll percentage calculation
2 parents 5fac8ea + f075dcb commit e52aaaf

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/js/core/factories/GridRenderContainer.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ angular.module('ui.grid')
303303
return this.getCanvasHeight() - this.getViewportHeight() + this.grid.scrollbarHeight;
304304
};
305305

306+
GridRenderContainer.prototype.getHorizontalScrollLength = function getHorizontalScrollLength() {
307+
return this.getCanvasWidth() - this.getViewportWidth() + this.grid.scrollbarWidth;
308+
};
309+
306310
GridRenderContainer.prototype.getCanvasWidth = function getCanvasWidth() {
307311
var self = this;
308312

@@ -375,7 +379,7 @@ angular.module('ui.grid')
375379
if (xDiff > 0) { this.grid.scrollDirection = uiGridConstants.scrollDirection.RIGHT; }
376380
if (xDiff < 0) { this.grid.scrollDirection = uiGridConstants.scrollDirection.LEFT; }
377381

378-
var horizScrollLength = (this.canvasWidth - this.getViewportWidth());
382+
var horizScrollLength = this.getHorizontalScrollLength();
379383
if (horizScrollLength !== 0) {
380384
horizScrollPercentage = newScrollLeft / horizScrollLength;
381385
}
@@ -487,8 +491,7 @@ angular.module('ui.grid')
487491

488492
// Calculate the scroll percentage according to the scrollLeft location, if no percentage was provided
489493
if ((typeof(scrollPercentage) === 'undefined' || scrollPercentage === null) && scrollLeft) {
490-
var horizScrollLength = (self.getCanvasWidth() - self.getViewportWidth());
491-
scrollPercentage = scrollLeft / horizScrollLength;
494+
scrollPercentage = scrollLeft / self.getHorizontalScrollLength();
492495
}
493496

494497
var colIndex = Math.ceil(Math.min(maxColumnIndex, maxColumnIndex * scrollPercentage));

0 commit comments

Comments
 (0)