From 835f51572c7b75fd5d23ed6851d4cfb7eaef599b Mon Sep 17 00:00:00 2001 From: ndudenhoeffer Date: Tue, 5 May 2015 17:16:01 -0500 Subject: [PATCH] fix(uiGridHeader): ensure that styles are rebuilt on explicit height Refactor setting of header heights to be more DRY and ensure that rebuildStyles is set when an explicit height is set. Do not set existing explicit heights to null before recalculating height. Fixes: #3394, #3382, #3409 --- src/js/core/factories/Grid.js | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/js/core/factories/Grid.js b/src/js/core/factories/Grid.js index 0f14be43d7..989ebf11a1 100644 --- a/src/js/core/factories/Grid.js +++ b/src/js/core/factories/Grid.js @@ -2065,8 +2065,8 @@ angular.module('ui.grid') } if (container.header || container.headerCanvas) { - container.explicitHeaderHeight = null; - container.explicitHeaderCanvasHeight = null; + container.explicitHeaderHeight = container.explicitHeaderHeight || null; + container.explicitHeaderCanvasHeight = container.explicitHeaderCanvasHeight || null; containerHeadersToRecalc.push(container); } @@ -2102,6 +2102,12 @@ angular.module('ui.grid') var maxHeaderHeight = 0; var maxHeaderCanvasHeight = 0; var i, container; + var getHeight = function(oldVal, newVal){ + if ( oldVal !== newVal){ + rebuildStyles = true; + } + return newVal; + }; for (i = 0; i < containerHeadersToRecalc.length; i++) { container = containerHeadersToRecalc[i]; @@ -2111,12 +2117,7 @@ angular.module('ui.grid') } if (container.header) { - var oldHeaderHeight = container.headerHeight; - var headerHeight = container.headerHeight = parseInt(gridUtil.outerElementHeight(container.header), 10); - - if (oldHeaderHeight !== headerHeight) { - rebuildStyles = true; - } + var headerHeight = container.headerHeight = getHeight(container.headerHeight, parseInt(gridUtil.outerElementHeight(container.header), 10)); // Get the "inner" header height, that is the height minus the top and bottom borders, if present. We'll use it to make sure all the headers have a consistent height var topBorder = gridUtil.getBorderSize(container.header, 'top'); @@ -2135,12 +2136,8 @@ angular.module('ui.grid') } if (container.headerCanvas) { - var oldHeaderCanvasHeight = container.headerCanvasHeight; - var headerCanvasHeight = container.headerCanvasHeight = parseInt(gridUtil.outerElementHeight(container.headerCanvas), 10); + var headerCanvasHeight = container.headerCanvasHeight = getHeight(container.headerCanvasHeight, parseInt(gridUtil.outerElementHeight(container.headerCanvas), 10)); - if (oldHeaderCanvasHeight !== headerCanvasHeight) { - rebuildStyles = true; - } // If the header doesn't have an explicit canvas height, save the largest header canvas height for use later // Explicit header heights are based off of the max we are calculating here. We never want to base the max on something we're setting explicitly @@ -2167,7 +2164,7 @@ angular.module('ui.grid') maxHeaderHeight > 0 && typeof(container.headerHeight) !== 'undefined' && container.headerHeight !== null && (container.explicitHeaderHeight || container.headerHeight < maxHeaderHeight) ) { - container.explicitHeaderHeight = maxHeaderHeight; + container.explicitHeaderHeight = getHeight(container.explicitHeaderHeight, maxHeaderHeight); } // Do the same as above except for the header canvas @@ -2175,7 +2172,7 @@ angular.module('ui.grid') maxHeaderCanvasHeight > 0 && typeof(container.headerCanvasHeight) !== 'undefined' && container.headerCanvasHeight !== null && (container.explicitHeaderCanvasHeight || container.headerCanvasHeight < maxHeaderCanvasHeight) ) { - container.explicitHeaderCanvasHeight = maxHeaderCanvasHeight; + container.explicitHeaderCanvasHeight = getHeight(container.explicitHeaderCanvasHeight, maxHeaderCanvasHeight); } }