Skip to content

Commit

Permalink
Fixes #363, allow displayName to be empty string
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
c0bra committed Apr 30, 2013
1 parent f93ed26 commit 46a992f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/classes/column.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
self.maxWidth = !colDef.maxWidth ? 9000 : colDef.maxWidth;
self.enableCellEdit = config.enableCellEdit || colDef.enableCellEdit;
self.headerRowHeight = config.headerRowHeight;
self.displayName = colDef.displayName || colDef.field;

// Use colDef.displayName as long as it's not undefined, otherwise default to the field name
self.displayName = (colDef.displayName === undefined) ? colDef.field : colDef.displayName;

self.index = config.index;
self.isAggCol = config.isAggCol;
self.cellClass = colDef.cellClass;
Expand Down
34 changes: 32 additions & 2 deletions test/unit/directivesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,38 @@ describe('directives', function () {
});
});
describe('column', function () {
it('should do something', function () {
//add work here
beforeEach(inject(function ($rootScope, $domUtilityService, $templateCache, $compile) {
$scope = $rootScope.$new();
$dUtils = $domUtilityService;
$linker = $compile;
$cache = $templateCache;

elm = angular.element(
'<div ng-grid="gridOptions" style="width: 1000px; height: 1000px"></div>'
);
scope = $rootScope;
scope.myData = [{name: "Moroni", age: 50},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34}];
scope.gridOptions = {
data: 'myData',
columnDefs: [
{ field : 'name' },
{ field : 'age', displayName: '' },
]
};
$compile(elm)(scope);
scope.$digest();
}));

it('should default to the field name when displayName is undefined', function() {
expect(elm.find('.ngHeaderText:eq(0)').text()).toEqual('name');
});

it('should not default to the column field name when the displayName is an empty string', function () {
expect(elm.find('.ngHeaderText:eq(1)').text()).toEqual('');
});
});
describe('domAccessProvider', function () {
Expand Down

0 comments on commit 46a992f

Please sign in to comment.