1

According to the docs,

{name:"M", phone:"1"} predicate will return an array of items which have property name containing "M" and property phone containing "1".

I want to implement an or between those keys. for example it should return the rows which have property name containing "M" and also the rows having phone property containing "1".

Is there any expression by which I can do that? or I'll have to implement a custom filter for the same

Salman
  • 9,299
  • 6
  • 40
  • 73
  • I think its a duplicate question. Please check this link http://stackoverflow.com/questions/15868248/how-to-filter-multiple-values-or-operation-in-angularjs – Janaki Sathiyamurthy Jul 03 '15 at 05:01
  • I see, so looks like custom filter is the only option. I was expecting something like this to be available just by tweaking filter expression. – Salman Jul 03 '15 at 05:07

2 Answers2

0

you may try array filter method

list.filter(function(element){ return element.name.includes('M'); })

Can also try jquery

$.grep:

$.grep(list, function(element){ return element.name.includes('M'); })

Abbas Galiyakotwala
  • 2,949
  • 4
  • 19
  • 34
0

Not sure if it's too early to conclude but it looks like creating a custom filter is the solution.

Here's it is,

.filter('orFilter', function () {
    return function (list, filterOn) {
        var out = [];
        for (var i = 0; i < list.length; i += 1) {
            var item = list[i];
            for (var key in filterOn) {
                var val = filterOn[key];
                if (~item[key].indexOf(val)) {
                    out.push(item);
                    break;
                }
            }
        }
        return out;
    }
});

I'll wait if someone posts a better solution.

Salman
  • 9,299
  • 6
  • 40
  • 73