sturoid
sturoid

Reputation: 2711

Or condition in filter

Is it possible to write a simple or condition in a filter like the following?:

formResponse in formResponses | filter: { formName: form } || filter:{ formCategory: formCategory }"

I know that the syntax is wrong but logically something similar. So if formCategory is set, it would filter by that and not formName, if formName is set it would filter by that and not formCategory. Right now it works as an and condition so it will filter by formName and formCategory.

Upvotes: 0

Views: 141

Answers (2)

Aidin
Aidin

Reputation: 2134

Usage:

formResponse in formResponses | customFilter: filter

Implementation:

angular.module('customFilter', [])
.filter('customFilter', [function () {
    'use strict';

return function (items, filter) {
    var filtered = [];
        angular.forEach(items, function(value, key) {
            if (filter.formName}
                   .....
            if (filter.formCategory)
                   ....
            if (passes filter criteria)
                  filtered.push(value);

        });
    }

    return filtered;
};
}]);

Upvotes: 1

sturoid
sturoid

Reputation: 2711

I got it working with the following:

<span ng-click="category='clinical'; name=''">Clinical Docs</span>
<span ng-click="name='intake'; category=''">Intake</span>

<div ng-repeat='formResponse in formResponses | filter: { formName: name } | filter: { formCategory: category }

Upvotes: 0

Related Questions