Skip to content

Commit e9ea9d4

Browse files
committed
fix(uiGrid): Use track by uid on columns
Track by name wasn't allowing for swapping out column definitions. If you re-used the same column names with different definitions this would cause your columns to lose their width CSS rules. Also re-enabled to unit test to check for this.
1 parent 1d9f81f commit e9ea9d4

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
<div class="ui-grid-header-canvas">
55
<div class="ui-grid-header-cell-wrapper" ng-style="colContainer.headerCellWrapperStyle()">
66
<div class="ui-grid-header-cell-row">
7-
<div class="ui-grid-header-cell ui-grid-clearfix" ng-repeat="col in colContainer.renderedColumns track by col.colDef.name" ui-grid-header-cell col="col" render-index="$index"></div>
7+
<div class="ui-grid-header-cell ui-grid-clearfix" ng-repeat="col in colContainer.renderedColumns track by col.uid" ui-grid-header-cell col="col" render-index="$index"></div>
88
</div>
99
</div>
1010
</div>
1111

1212
</div>
1313
</div>
14-
</div>
14+
</div>
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.colDef.name" class="ui-grid-cell" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell></div>
2-
1+
<div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.uid" class="ui-grid-cell" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell></div>

test/unit/core/directives/uiGridCell.spec.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('uiGridCell', function () {
6060
recompile();
6161
var displayHtml = gridCell.html();
6262
expect(gridCell.hasClass('funcCellClass')).toBe(true);
63-
63+
6464
$scope.col.noClass = true;
6565
$scope.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN );
6666
expect(gridCell.hasClass('funcCellClass')).toBe(false);
@@ -80,18 +80,17 @@ describe('uiGridCell', function () {
8080
recompile();
8181
var displayHtml = gridCell.html();
8282
expect(gridCell.hasClass('funcCellClass')).toBe(true);
83-
83+
8484
$scope.col = new GridColumn({name: 'col2'}, 0, $scope.grid);
8585
$scope.$digest();
8686
expect(gridCell.hasClass('funcCellClass')).toBe(false);
8787
}));
8888
*/
8989
});
90-
90+
9191
// Don't run this on IE9. The behavior looks correct when testing interactively but these tests fail
92-
/* not a valid test.....we think
9392
if (!navigator.userAgent.match(/MSIE\s+9\.0/)) {
94-
it("should change a column's class when its uid changes", inject(function (gridUtil, $compile, uiGridConstants) {
93+
iit("should change a column's class when its uid changes", inject(function (gridUtil, $compile, uiGridConstants) {
9594
// Reset the UIDs (used by columns) so they're fresh and clean
9695
gridUtil.resetUids();
9796

@@ -146,5 +145,5 @@ describe('uiGridCell', function () {
146145
angular.element(gridElm).remove();
147146
}));
148147
}
149-
*/
150-
});
148+
149+
});

0 commit comments

Comments
 (0)