Skip to content

Commit

Permalink
[hotfix/3527]
Browse files Browse the repository at this point in the history
 - adjustColumns now calculates the colIndex instead of guessing it scrollpercentage
  • Loading branch information
Leo Morgenstern authored and mportuga committed Jul 31, 2021
1 parent 3ff57e0 commit ed76f02
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
5 changes: 2 additions & 3 deletions packages/core/src/js/factories/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -2250,13 +2250,12 @@ angular.module('ui.grid')
var container = self.renderContainers[i],
prevScrollTop = getPrevScrollValue(rowsAdded, container.prevScrollTop),
prevScrollLeft = getPrevScrollValue(rowsAdded, container.prevScrollLeft),
prevScrolltopPercentage = rowsAdded || prevScrollTop > 0 ? null : container.prevScrolltopPercentage,
prevScrollleftPercentage = rowsAdded || prevScrollLeft > 0 ? null : container.prevScrollleftPercentage;
prevScrolltopPercentage = rowsAdded || prevScrollTop > 0 ? null : container.prevScrolltopPercentage;

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

container.adjustRows(prevScrollTop, prevScrolltopPercentage);
container.adjustColumns(prevScrollLeft, prevScrollleftPercentage);
container.adjustColumns(prevScrollLeft);
}
};

Expand Down
30 changes: 17 additions & 13 deletions packages/core/src/js/factories/GridRenderContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ angular.module('ui.grid')
scrollLeft = (this.getCanvasWidth() - this.getViewportWidth()) * scrollPercentage;
}

this.adjustColumns(scrollLeft, scrollPercentage);
this.adjustColumns(scrollLeft);

this.prevScrollLeft = scrollLeft;
this.prevScrollleftPercentage = scrollPercentage;
Expand Down Expand Up @@ -458,25 +458,15 @@ angular.module('ui.grid')
self.prevRowScrollIndex = rowIndex;
};

GridRenderContainer.prototype.adjustColumns = function adjustColumns(scrollLeft, scrollPercentage) {
GridRenderContainer.prototype.adjustColumns = function adjustColumns(scrollLeft) {
var self = this;

var minCols = self.minColumnsToRender();

var columnCache = self.visibleColumnCache;
var maxColumnIndex = columnCache.length - minCols;

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

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

// Define a max row index that we can't scroll past
if (colIndex > maxColumnIndex) {
colIndex = maxColumnIndex;
}
var colIndex = Math.min(maxColumnIndex, self.getLeftIndex(scrollLeft));

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

GridRenderContainer.prototype.getLeftIndex = function getLeftIndex(scrollLeft) {
var wholeLeftWidth = 0;
var index = 0
for (index; index < this.visibleColumnCache.length; index++) {
if(this.visibleColumnCache[index] && this.visibleColumnCache[index].visible){
//accumulate the whole width of columns on the left side, till the point of visibility is surpassed, this is our wanted index
wholeLeftWidth += this.visibleColumnCache[index].drawnWidth;
if(wholeLeftWidth >= scrollLeft)
break;
}
}
return index;
}

// Method for updating the visible rows
GridRenderContainer.prototype.updateViewableRowRange = function updateViewableRowRange(renderedRange) {
// Slice out the range of rows from the data
Expand Down

0 comments on commit ed76f02

Please sign in to comment.