Skip to content

Commit ed76f02

Browse files
Leo Morgensternmportuga
authored andcommitted
[hotfix/3527]
- adjustColumns now calculates the colIndex instead of guessing it scrollpercentage
1 parent 3ff57e0 commit ed76f02

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

packages/core/src/js/factories/Grid.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,13 +2250,12 @@ angular.module('ui.grid')
22502250
var container = self.renderContainers[i],
22512251
prevScrollTop = getPrevScrollValue(rowsAdded, container.prevScrollTop),
22522252
prevScrollLeft = getPrevScrollValue(rowsAdded, container.prevScrollLeft),
2253-
prevScrolltopPercentage = rowsAdded || prevScrollTop > 0 ? null : container.prevScrolltopPercentage,
2254-
prevScrollleftPercentage = rowsAdded || prevScrollLeft > 0 ? null : container.prevScrollleftPercentage;
2253+
prevScrolltopPercentage = rowsAdded || prevScrollTop > 0 ? null : container.prevScrolltopPercentage;
22552254

22562255
// gridUtil.logDebug('redrawing container', i);
22572256

22582257
container.adjustRows(prevScrollTop, prevScrolltopPercentage);
2259-
container.adjustColumns(prevScrollLeft, prevScrollleftPercentage);
2258+
container.adjustColumns(prevScrollLeft);
22602259
}
22612260
};
22622261

packages/core/src/js/factories/GridRenderContainer.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ angular.module('ui.grid')
401401
scrollLeft = (this.getCanvasWidth() - this.getViewportWidth()) * scrollPercentage;
402402
}
403403

404-
this.adjustColumns(scrollLeft, scrollPercentage);
404+
this.adjustColumns(scrollLeft);
405405

406406
this.prevScrollLeft = scrollLeft;
407407
this.prevScrollleftPercentage = scrollPercentage;
@@ -458,25 +458,15 @@ angular.module('ui.grid')
458458
self.prevRowScrollIndex = rowIndex;
459459
};
460460

461-
GridRenderContainer.prototype.adjustColumns = function adjustColumns(scrollLeft, scrollPercentage) {
461+
GridRenderContainer.prototype.adjustColumns = function adjustColumns(scrollLeft) {
462462
var self = this;
463463

464464
var minCols = self.minColumnsToRender();
465465

466466
var columnCache = self.visibleColumnCache;
467467
var maxColumnIndex = columnCache.length - minCols;
468468

469-
// Calculate the scroll percentage according to the scrollLeft location, if no percentage was provided
470-
if ((typeof(scrollPercentage) === 'undefined' || scrollPercentage === null) && scrollLeft) {
471-
scrollPercentage = scrollLeft / self.getHorizontalScrollLength();
472-
}
473-
474-
var colIndex = Math.ceil(Math.min(maxColumnIndex, maxColumnIndex * scrollPercentage));
475-
476-
// Define a max row index that we can't scroll past
477-
if (colIndex > maxColumnIndex) {
478-
colIndex = maxColumnIndex;
479-
}
469+
var colIndex = Math.min(maxColumnIndex, self.getLeftIndex(scrollLeft));
480470

481471
var newRange = [];
482472
if (columnCache.length > self.grid.options.columnVirtualizationThreshold && self.getCanvasWidth() > self.getViewportWidth()) {
@@ -496,6 +486,20 @@ angular.module('ui.grid')
496486
self.prevColumnScrollIndex = colIndex;
497487
};
498488

489+
GridRenderContainer.prototype.getLeftIndex = function getLeftIndex(scrollLeft) {
490+
var wholeLeftWidth = 0;
491+
var index = 0
492+
for (index; index < this.visibleColumnCache.length; index++) {
493+
if(this.visibleColumnCache[index] && this.visibleColumnCache[index].visible){
494+
//accumulate the whole width of columns on the left side, till the point of visibility is surpassed, this is our wanted index
495+
wholeLeftWidth += this.visibleColumnCache[index].drawnWidth;
496+
if(wholeLeftWidth >= scrollLeft)
497+
break;
498+
}
499+
}
500+
return index;
501+
}
502+
499503
// Method for updating the visible rows
500504
GridRenderContainer.prototype.updateViewableRowRange = function updateViewableRowRange(renderedRange) {
501505
// Slice out the range of rows from the data

0 commit comments

Comments
 (0)