Skip to content

Commit

Permalink
added an 'aggregationLabel' attribute on colDef to be able to overrid…
Browse files Browse the repository at this point in the history
…e the i18n translation

fixed test

fixed whitespaces

added an 'aggregationLabel' attribute on colDef to be able to override the i18n translation

fixed test

fixed whitespaces
  • Loading branch information
pedroclayman committed Dec 3, 2014
1 parent e3c3ac4 commit cfcd55d
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 @@ -671,17 +671,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 cfcd55d

Please sign in to comment.