angular-filter
angular-filter copied to clipboard
filter collection with "groupBy" when keys can be null / undefined.
https://github.com/a8m/angular-filter/blob/91ae1bfe75a4e747c2c52eab2065565aeb39c97e/src/_filter/collection/group-by.js#L36-L43
Because of memoization, special values such as null
or undefined
converted to their string equivalent 'null'
and 'undefined'
.
e.g. I am trying to have an accordion-group
whose heading is the name of the group, however I cannot test for null
or undefined
explicitly.
<accordion-group is-open="group.open" ng-repeat="(groupKey, groupData) in originalData | groupBy:radioButtonGroupBy">
<accordion-heading><span bindonce bo-text="groupKey||'--'"></span><!-- broken -->
<i class="glyphicon" ng-class="{'caret-down': group.open, 'caret-right': !group.open}"></i>
</accordion-heading>
...something with groupData...
Can you provide some fiddle/jsbin @dnozay ? Thx.
will do.
http://jsfiddle.net/unn62n16/1/
Any changes with that issue? It would seem, that the obvious solution is to add else part and push values without group into virtual group with empty string name.
UPD:
There is also an issue with referencing items by $index
, since there is an inner ng-repeat
. But maybe it is a correct behaviour.
~~Can you please add a conditional to if(!isObject(collection) || isUndefined(property)) { to test for property !== 'null' or undefined~~
Here we go in the groupBy, add key
to the forEach and call this out.
forEach( collection, function( elm, key ) {
if ( isUndefined(elm[property]) || elm[property] == null ) {
result[key] = [elm];
return;
}