From 46a992f39d096afff266f175ec7b3f6ba80ec953 Mon Sep 17 00:00:00 2001 From: Brian Hann Date: Mon, 29 Apr 2013 10:37:09 -0500 Subject: [PATCH] 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. --- src/classes/column.js | 5 ++++- test/unit/directivesSpec.js | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) 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 () {