Skip to content

Commit

Permalink
fix: Incorrect scroll percentage calculation in scrollHorizontal method
Browse files Browse the repository at this point in the history
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.
vkorolev authored and Valentin Korolev committed Feb 20, 2016
1 parent c61f680 commit f075dcb
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/js/core/factories/GridRenderContainer.js
Original file line number Diff line number Diff line change
@@ -303,6 +303,10 @@ angular.module('ui.grid')
return this.getCanvasHeight() - this.getViewportHeight() + this.grid.scrollbarHeight;
};

GridRenderContainer.prototype.getHorizontalScrollLength = function getHorizontalScrollLength() {
return this.getCanvasWidth() - this.getViewportWidth() + this.grid.scrollbarWidth;
};

GridRenderContainer.prototype.getCanvasWidth = function getCanvasWidth() {
var self = this;

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

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

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

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

0 comments on commit f075dcb

Please sign in to comment.