Skip to content

Commit f075dcb

Browse files
vkorolevValentin Korolev
authored and
Valentin Korolev
committed
fix: Incorrect scroll percentage calculation in scrollHorizontal method
Change scroll percentage calculation approach. Use getScrollWidth instead of getCanvasWidth as a denominator. Add width of scroll to scroll length for percentage not to exceed 1.
1 parent c61f680 commit f075dcb

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/js/core/factories/GridRenderContainer.js

+6-3
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)