angular-filter icon indicating copy to clipboard operation
angular-filter copied to clipboard

filter collection with "groupBy" when keys can be null / undefined.

Open dnozay opened this issue 9 years ago • 5 comments

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...

dnozay avatar Apr 13 '15 23:04 dnozay

Can you provide some fiddle/jsbin @dnozay ? Thx.

a8m avatar Apr 14 '15 04:04 a8m

will do.

dnozay avatar Apr 14 '15 05:04 dnozay

http://jsfiddle.net/unn62n16/1/

dnozay avatar Apr 14 '15 06:04 dnozay

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.

jeserkin avatar Dec 14 '15 12:12 jeserkin

~~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;
          }

ericjames avatar Sep 11 '16 03:09 ericjames