Skip to content

Commit 65ad61f

Browse files
author
ndudenhoeffer
committed
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
1 parent efd3798 commit 65ad61f

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

Diff for: src/js/core/factories/Grid.js

+12-15
Original file line numberDiff line numberDiff line change
@@ -2065,8 +2065,8 @@ angular.module('ui.grid')
20652065
}
20662066

20672067
if (container.header || container.headerCanvas) {
2068-
container.explicitHeaderHeight = null;
2069-
container.explicitHeaderCanvasHeight = null;
2068+
container.explicitHeaderHeight = container.explicitHeaderHeight || null;
2069+
container.explicitHeaderCanvasHeight = container.explicitHeaderCanvasHeight || null;
20702070

20712071
containerHeadersToRecalc.push(container);
20722072
}
@@ -2102,6 +2102,12 @@ angular.module('ui.grid')
21022102
var maxHeaderHeight = 0;
21032103
var maxHeaderCanvasHeight = 0;
21042104
var i, container;
2105+
var getHeight = function(oldVal, newVal){
2106+
if ( oldVal !== newVal){
2107+
rebuildStyles = true;
2108+
}
2109+
return newVal;
2110+
};
21052111
for (i = 0; i < containerHeadersToRecalc.length; i++) {
21062112
container = containerHeadersToRecalc[i];
21072113

@@ -2111,12 +2117,7 @@ angular.module('ui.grid')
21112117
}
21122118

21132119
if (container.header) {
2114-
var oldHeaderHeight = container.headerHeight;
2115-
var headerHeight = container.headerHeight = parseInt(gridUtil.outerElementHeight(container.header), 10);
2116-
2117-
if (oldHeaderHeight !== headerHeight) {
2118-
rebuildStyles = true;
2119-
}
2120+
var headerHeight = container.headerHeight = getHeight(container.headerHeight, parseInt(gridUtil.outerElementHeight(container.header), 10));
21202121

21212122
// 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
21222123
var topBorder = gridUtil.getBorderSize(container.header, 'top');
@@ -2135,12 +2136,8 @@ angular.module('ui.grid')
21352136
}
21362137

21372138
if (container.headerCanvas) {
2138-
var oldHeaderCanvasHeight = container.headerCanvasHeight;
2139-
var headerCanvasHeight = container.headerCanvasHeight = parseInt(gridUtil.outerElementHeight(container.headerCanvas), 10);
2139+
var headerCanvasHeight = container.headerCanvasHeight = getHeight(container.headerCanvasHeight, parseInt(gridUtil.outerElementHeight(container.headerCanvas), 10));
21402140

2141-
if (oldHeaderCanvasHeight !== headerCanvasHeight) {
2142-
rebuildStyles = true;
2143-
}
21442141

21452142
// If the header doesn't have an explicit canvas height, save the largest header canvas height for use later
21462143
// 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,15 +2164,15 @@ angular.module('ui.grid')
21672164
maxHeaderHeight > 0 && typeof(container.headerHeight) !== 'undefined' && container.headerHeight !== null &&
21682165
(container.explicitHeaderHeight || container.headerHeight < maxHeaderHeight)
21692166
) {
2170-
container.explicitHeaderHeight = maxHeaderHeight;
2167+
container.explicitHeaderHeight = getHeight(container.explicitHeaderHeight, maxHeaderHeight);
21712168
}
21722169

21732170
// Do the same as above except for the header canvas
21742171
if (
21752172
maxHeaderCanvasHeight > 0 && typeof(container.headerCanvasHeight) !== 'undefined' && container.headerCanvasHeight !== null &&
21762173
(container.explicitHeaderCanvasHeight || container.headerCanvasHeight < maxHeaderCanvasHeight)
21772174
) {
2178-
container.explicitHeaderCanvasHeight = maxHeaderCanvasHeight;
2175+
container.explicitHeaderCanvasHeight = getHeight(container.explicitHeaderCanvasHeight, maxHeaderCanvasHeight);
21792176
}
21802177
}
21812178

0 commit comments

Comments
 (0)