From 509e0071b1929adecb6e75be20166902a70452ad Mon Sep 17 00:00:00 2001 From: jcompagner Date: Tue, 23 Dec 2014 16:16:39 +0100 Subject: [PATCH] fix(Grid): Redraw needs scrollTop when adding rows Regression Fix for #2357 the scrollPercentage is not correct if there are added rows, because then the scrollPercentage should be recalculated. --- src/js/core/directives/ui-grid.js | 2 +- src/js/core/factories/Grid.js | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/js/core/directives/ui-grid.js b/src/js/core/directives/ui-grid.js index 2a2d56ed91..4c65ec5254 100644 --- a/src/js/core/directives/ui-grid.js +++ b/src/js/core/directives/ui-grid.js @@ -108,7 +108,7 @@ self.grid.modifyRows(newData) .then(function () { // if (self.viewport) { - self.grid.redrawInPlace(); + self.grid.redrawInPlace(true); // } $scope.$evalAsync(function() { diff --git a/src/js/core/factories/Grid.js b/src/js/core/factories/Grid.js index b1f4418db6..a13bbbdfc7 100644 --- a/src/js/core/factories/Grid.js +++ b/src/js/core/factories/Grid.js @@ -2001,9 +2001,10 @@ angular.module('ui.grid') * @name redrawCanvas * @methodOf ui.grid.class:Grid * @description Redraw the rows and columns based on our current scroll position + * @param {boolean} [rowsAdded] Optional to indicate rows are added and the scroll percentage must be recalculated * */ - Grid.prototype.redrawInPlace = function redrawInPlace() { + Grid.prototype.redrawInPlace = function redrawInPlace(rowsAdded) { // gridUtil.logDebug('redrawInPlace'); var self = this; @@ -2012,9 +2013,15 @@ angular.module('ui.grid') var container = self.renderContainers[i]; // gridUtil.logDebug('redrawing container', i); - - container.adjustRows(null, container.prevScrolltopPercentage, true); - container.adjustColumns(null, container.prevScrollleftPercentage); + + if (rowsAdded) { + container.adjustRows(container.prevScrollTop, null); + container.adjustColumns(container.prevScrollTop, null); + } + else { + container.adjustRows(null, container.prevScrolltopPercentage); + container.adjustColumns(null, container.prevScrollleftPercentage); + } } };