Skip to content

Commit

Permalink
fix(uiGridHeader): ensure that styles are rebuilt on explicit height
Browse files Browse the repository at this point in the history
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: angular-ui#3394, angular-ui#3382, angular-ui#3409
  • Loading branch information
ndudenhoeffer committed May 7, 2015
1 parent aa56355 commit 835f515
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/js/core/factories/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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];

Expand All @@ -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');
Expand All @@ -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
Expand All @@ -2167,15 +2164,15 @@ 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
if (
maxHeaderCanvasHeight > 0 && typeof(container.headerCanvasHeight) !== 'undefined' && container.headerCanvasHeight !== null &&
(container.explicitHeaderCanvasHeight || container.headerCanvasHeight < maxHeaderCanvasHeight)
) {
container.explicitHeaderCanvasHeight = maxHeaderCanvasHeight;
container.explicitHeaderCanvasHeight = getHeight(container.explicitHeaderCanvasHeight, maxHeaderCanvasHeight);
}
}

Expand Down

0 comments on commit 835f515

Please sign in to comment.