diff --git a/src/classes/column.js b/src/classes/column.js index c9bfb1fcdd..502adf17dd 100644 --- a/src/classes/column.js +++ b/src/classes/column.js @@ -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; diff --git a/test/unit/directivesSpec.js b/test/unit/directivesSpec.js index 9b4205de63..b49283478e 100644 --- a/test/unit/directivesSpec.js +++ b/test/unit/directivesSpec.js @@ -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( + '
' + ); + 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 () {