Skip to content

Commit 46a992f

Browse files
committedApr 30, 2013
Fixes #363, allow displayName to be empty string
When the columnDef displayName property was an empty string, the column class was defaulting to using the field name in the header template. Now it will allow an empty string and will only use the field name if displayName is undefined.
1 parent f93ed26 commit 46a992f

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed
 

‎src/classes/column.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
self.maxWidth = !colDef.maxWidth ? 9000 : colDef.maxWidth;
1313
self.enableCellEdit = config.enableCellEdit || colDef.enableCellEdit;
1414
self.headerRowHeight = config.headerRowHeight;
15-
self.displayName = colDef.displayName || colDef.field;
15+
16+
// Use colDef.displayName as long as it's not undefined, otherwise default to the field name
17+
self.displayName = (colDef.displayName === undefined) ? colDef.field : colDef.displayName;
18+
1619
self.index = config.index;
1720
self.isAggCol = config.isAggCol;
1821
self.cellClass = colDef.cellClass;

‎test/unit/directivesSpec.js

+32-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,38 @@ describe('directives', function () {
8888
});
8989
});
9090
describe('column', function () {
91-
it('should do something', function () {
92-
//add work here
91+
beforeEach(inject(function ($rootScope, $domUtilityService, $templateCache, $compile) {
92+
$scope = $rootScope.$new();
93+
$dUtils = $domUtilityService;
94+
$linker = $compile;
95+
$cache = $templateCache;
96+
97+
elm = angular.element(
98+
'<div ng-grid="gridOptions" style="width: 1000px; height: 1000px"></div>'
99+
);
100+
scope = $rootScope;
101+
scope.myData = [{name: "Moroni", age: 50},
102+
{name: "Tiancum", age: 43},
103+
{name: "Jacob", age: 27},
104+
{name: "Nephi", age: 29},
105+
{name: "Enos", age: 34}];
106+
scope.gridOptions = {
107+
data: 'myData',
108+
columnDefs: [
109+
{ field : 'name' },
110+
{ field : 'age', displayName: '' },
111+
]
112+
};
113+
$compile(elm)(scope);
114+
scope.$digest();
115+
}));
116+
117+
it('should default to the field name when displayName is undefined', function() {
118+
expect(elm.find('.ngHeaderText:eq(0)').text()).toEqual('name');
119+
});
120+
121+
it('should not default to the column field name when the displayName is an empty string', function () {
122+
expect(elm.find('.ngHeaderText:eq(1)').text()).toEqual('');
93123
});
94124
});
95125
describe('domAccessProvider', function () {

0 commit comments

Comments
 (0)
Please sign in to comment.