Skip to content

Commit

Permalink
feat(grouping): Add option groupingNullLabel, to group null and undef…
Browse files Browse the repository at this point in the history
…ined values together.

 Fixes #3271
  • Loading branch information
ndudenhoeffer committed May 6, 2015
1 parent efd3798 commit 9fbb1b8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/features/grouping/js/grouping.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,15 @@
* <br/>Defaults to true
*/
gridOptions.groupingShowCounts = gridOptions.groupingShowCounts !== false;

/**
* @ngdoc object
* @name groupingNullLabel
* @propertyOf ui.grid.grouping.api:GridOptions
* @description The string to use for the grouping header row label on rows which contain a null or undefined value in the grouped column.
* <br/>Defaults to "Null"
*/
gridOptions.groupingNullLabel = gridOptions.groupingNullLabel || 'Null';
},


Expand Down Expand Up @@ -1140,7 +1149,7 @@
var updateProcessingState = function( groupFieldState, stateIndex ) {
var fieldValue = grid.getCellValue(row, groupFieldState.col);
if ( typeof(fieldValue) === 'undefined' || fieldValue === null ){
return;
fieldValue = grid.options.groupingNullLabel;
}

if ( !row.visible ){
Expand Down Expand Up @@ -1287,6 +1296,9 @@

// TODO: can't just use entity like this, have to use get cell value, need col for that
var newValue = grid.getCellValue(renderableRows[rowIndex], col);
if ( typeof(newValue) === 'undefined' || newValue === null ) {
newValue = grid.options.groupingNullLabel;
}
headerRow.entity[fieldName] = newValue;
headerRow.groupLevel = stateIndex;
headerRow.groupHeader = true;
Expand Down

1 comment on commit 9fbb1b8

@prettycode
Copy link
Contributor

@prettycode prettycode commented on 9fbb1b8 May 31, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we conflating undefined and null as being equal to one another, when they're not?

null is a value, whereas typeof(x) === 'undefined' means there is no value.

As a workaround, I have to walk all my datasets and replace null values with the string "null" before I hand off the data to ui-grid, so users can distinguish a cell value of null from a cell with no value (undefined). Bummer.

Is my workaround required, or is there another way to instruct ui-grid to disambiguate null values from fields with no values?

Please sign in to comment.