Skip to content

Commit

Permalink
Merge pull request angular-ui#2237 from pedroclayman/master
Browse files Browse the repository at this point in the history
added an 'aggregationLabel' attribute on colDef
  • Loading branch information
c0bra committed Dec 8, 2014
2 parents e6cf438 + cfcd55d commit d1bb517
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/js/core/factories/GridColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,17 +676,22 @@ angular.module('ui.grid')
* @ngdoc function
* @name getAggregationText
* @methodOf ui.grid.class:GridColumn
* @description Gets the aggregation label using i18n, including
* deciding whether or not to display based on colDef.aggregationHideLabel
*
* @description Gets the aggregation label from colDef.aggregationLabel if
* specified or by using i18n, including deciding whether or not to display
* based on colDef.aggregationHideLabel.
*
* @param {string} label the i18n lookup value to use for the column label
*
*/
GridColumn.prototype.getAggregationText = function () {
var self = this;
if ( self.colDef.aggregationHideLabel ){
return '';
} else {
}
else if ( self.colDef.aggregationLabel ) {
return self.colDef.aggregationLabel;
}
else {
switch ( self.colDef.aggregationType ){
case uiGridConstants.aggregationTypes.count:
return i18nService.getSafeText('aggregation.count');
Expand Down
30 changes: 30 additions & 0 deletions test/unit/core/factories/GridColumn.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,36 @@ describe('GridColumn factory', function () {
expect(grid.columns[1].getAggregationValue()).toEqual(5);
expect(grid.columns[1].getAggregationText()).toEqual('');
});

it('max, with custom label', function() {
var customLabel = 'custom label';

grid.options.columnDefs[1].aggregationType = uiGridConstants.aggregationTypes.max;
grid.options.columnDefs[1].aggregationLabel = customLabel;
grid.options.columnDefs[1].aggregationHideLabel = false;

buildCols();
grid.modifyRows(grid.options.data);
grid.setVisibleRows(grid.rows);

expect(grid.columns[1].getAggregationValue()).toEqual(5);
expect(grid.columns[1].getAggregationText()).toEqual(customLabel);
});

it('max, with custom label while also being hidden', function() {
var customLabel = 'custom label';

grid.options.columnDefs[1].aggregationType = uiGridConstants.aggregationTypes.max;
grid.options.columnDefs[1].aggregationLabel = customLabel;
grid.options.columnDefs[1].aggregationHideLabel = true;

buildCols();
grid.modifyRows(grid.options.data);
grid.setVisibleRows(grid.rows);

expect(grid.columns[1].getAggregationValue()).toEqual(5);
expect(grid.columns[1].getAggregationText()).toEqual('');
});
});

describe('unsort', function() {
Expand Down

0 comments on commit d1bb517

Please sign in to comment.