Skip to content

Commit b156285

Browse files
committed
fix(uiGridHeader): Fix header height calculation
When the header cells were long enough that they wrapped inside the header container, they were causing the header height to be calcuated as double what it should have been. This has been fixed by making the header cells floating, and defaulting their width to 0. Their width is calculated dynamically within uiGridStyle.
1 parent 8670fdc commit b156285

File tree

4 files changed

+36
-26
lines changed

4 files changed

+36
-26
lines changed

src/js/core/directives/ui-grid.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@
156156
}
157157
var col = self.getColumn(colDef.field);
158158

159-
if (!col) {
159+
//if (!col) {
160160
col = new GridColumn(colDef, index);
161161
self.columns.push(col);
162-
}
162+
//}
163163

164164
self.columnBuilders.forEach(function (builder) {
165165
builderPromises.push(builder.call(self, colDef, col, self.options));
@@ -259,7 +259,7 @@
259259
for (var i = 0; i < newRows.length; i++) {
260260
this.renderedRows.length = newRows.length;
261261

262-
this.renderedRows[i] =newRows[i];
262+
this.renderedRows[i] = newRows[i];
263263
}
264264
};
265265

@@ -284,7 +284,6 @@
284284
// TODO(c0bra): account for footer height
285285
Grid.prototype.getViewportHeight = function () {
286286
var viewPortHeight = this.gridHeight - this.headerHeight;
287-
$log.debug('viewPortHeight', viewPortHeight);
288287
return viewPortHeight;
289288
};
290289

@@ -476,17 +475,16 @@
476475

477476

478477
$scope.$watch(function () { return self.grid.styleComputations; }, function() {
479-
self.grid.buildStyles($scope);
478+
self.refreshCanvas();
480479
});
481480

482481
// Refresh the canvas drawable size
483482
$scope.grid.refreshCanvas = self.refreshCanvas = function() {
483+
self.grid.buildStyles($scope);
484+
484485
if (self.header) {
485486
self.grid.headerHeight = gridUtil.outerElementHeight(self.header);
486-
$log.debug('self.grid.headerHeight', self.grid.headerHeight);
487487
}
488-
489-
self.grid.buildStyles($scope);
490488
};
491489

492490
//todo: throttle this event?
@@ -548,6 +546,8 @@ module.directive('uiGrid',
548546
post: function ($scope, $elm, $attrs, uiGridCtrl) {
549547
$log.debug('ui-grid postlink');
550548

549+
uiGridCtrl.grid.element = $elm;
550+
551551
uiGridCtrl.grid.gridWidth = $scope.gridWidth = gridUtil.elementWidth($elm);
552552
uiGridCtrl.grid.gridHeight = $scope.gridHeight = gridUtil.elementHeight($elm);
553553

@@ -568,14 +568,14 @@ module.directive('uiGrid',
568568

569569
return {
570570
pre: function($scope, $elm) {
571-
$log.debug('uiGridCell pre-link');
571+
// $log.debug('uiGridCell pre-link');
572572
var html = $scope.col.cellTemplate
573573
.replace(uiGridConstants.COL_FIELD, 'row.entity.' + $scope.col.colDef.field);
574574
var cellElement = $compile(html)($scope);
575575
$elm.append(cellElement);
576576
},
577577
post: function($scope, $elm) {
578-
$log.debug('uiGridCell post-link');
578+
// $log.debug('uiGridCell post-link');
579579
}
580580
};
581581
}

src/less/header.less

+24-9
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,38 @@
77
overflow: hidden;
88
font-weight: bold;
99

10-
.gradient(#f3f3f3, #eee, #fff);
10+
.gradient(#f3f3f3, #eee, #fff);
11+
}
1112

12-
// &:before, &:after {
13-
// content:"";
14-
// display:table;
15-
// }
13+
.ui-grid-header {
14+
// Clearfix for floating header cells
15+
&:before, &:after {
16+
content: "";
17+
display: table;
18+
line-height: 0;
19+
}
1620

17-
// &:after {
18-
// clear:both;
19-
// }
21+
&:after {
22+
clear:both;
23+
}
2024
}
2125

2226
.ui-grid-header-cell {
23-
// position: absolute;
2427
position: relative;
2528
float: left;
2629
top: 0;
2730
bottom: 0;
2831
background-color: inherit;
32+
33+
// Default to width 0 so header height can calculate right. Otherwise
34+
// the header cells will flow onto the next line of the header container
35+
// and cause the header height to be calculated as twice the height
36+
// it should be. The column widths are calculated dynamically
37+
width: 0;
38+
}
39+
40+
// Make vertical bar in header row fill the height of the cell completely
41+
.ui-grid-header .ui-grid-vertical-bar {
42+
top: 0;
43+
bottom: 0;
2944
}

src/templates/ui-grid/ui-grid-header.html

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<div class="ui-grid-top-panel">
22
<div class="ui-grid-header">
3-
<div ng-repeat="col in grid.columns" class="ui-grid-header-cell col{{ $index }}"> <!-- ng-style="{ height: col.headerRowHeight }" -->
4-
<div class="ui-grid-vertical-bar">&nbsp;</div> <!-- ng-style="{height: col.headerRowHeight}" ng-class="{ ngVerticalBarVisible: !$last }" -->
5-
<!-- <div ng-header-cell></div> -->
3+
<div ng-repeat="col in grid.columns" class="ui-grid-header-cell col{{ $index }}">
4+
<div class="ui-grid-vertical-bar">&nbsp;</div>
65
<div class="ui-grid-cell-contents">{{ col.displayName }}</span></div>
76
</div>
87
</div>

src/templates/ui-grid/ui-grid.html

-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
height: {{ grid.getCanvasHeight() }}px;
1414
}
1515

16-
.grid{{ grid.id }} .ui-grid-header, .grid{{ grid.id }} .ui-grid-header-cell .ui-grid-vertical-bar {
17-
height: {{ grid.options.headerRowHeight }}px;
18-
}
19-
2016
.grid{{ grid.id }} .ui-grid-row, .grid{{ grid.id }} .ui-grid-cell, .grid{{ grid.id }} .ui-grid-cell .ui-grid-vertical-bar {
2117
height: {{ grid.options.rowHeight }}px;
2218
}

0 commit comments

Comments
 (0)