From ed76f02090f3510d555cacdae03f1edad849d27a Mon Sep 17 00:00:00 2001 From: Leo Morgenstern Date: Thu, 22 Jul 2021 08:33:53 +0200 Subject: [PATCH] [hotfix/3527] - adjustColumns now calculates the colIndex instead of guessing it scrollpercentage --- packages/core/src/js/factories/Grid.js | 5 ++-- .../src/js/factories/GridRenderContainer.js | 30 +++++++++++-------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/packages/core/src/js/factories/Grid.js b/packages/core/src/js/factories/Grid.js index 0dd39480e5..02098689f4 100644 --- a/packages/core/src/js/factories/Grid.js +++ b/packages/core/src/js/factories/Grid.js @@ -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); } }; diff --git a/packages/core/src/js/factories/GridRenderContainer.js b/packages/core/src/js/factories/GridRenderContainer.js index 8204dc591e..9c7c13d359 100644 --- a/packages/core/src/js/factories/GridRenderContainer.js +++ b/packages/core/src/js/factories/GridRenderContainer.js @@ -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; @@ -458,7 +458,7 @@ 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(); @@ -466,17 +466,7 @@ angular.module('ui.grid') 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()) { @@ -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