Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

$filter('filter')(array, expression) does not work with more than one nested property #9698

Closed
barroudjo opened this issue Oct 20, 2014 · 5 comments

Comments

@barroudjo
Copy link

My Array:

var array = [{
    length : 10,
    answerer : {
         email : 'test@test.com',
         name : 'test user'
    }
},
{
    length : 20,
    answerer : {
        email : 'admin@admin.com',
        name : 'admin'
    }
}];

the filter expression:

var expression = {
    answerer : {
        name : 'test',
        email: 'adm'
    }
};

Then filtering based on this:

var filteredData = $filter('filter')(array, expression)

I expect to get the empty array. However I get the full array, as if no filtering was done !
But if I filter on only one element, for example:

var expression = { answerer : { email: 'adm' } };

It works as expected and returns only the second element of array.

I also tried to define differently my filter expression:

var expression = { 'answerer.email': 'adm' } };

But this returns no result at all.

So it would seem there is a bug when filtering on more than one nested property.

A workaround could be to use a custom comparator functions. Any other ideas (besides flattening my array...) ?

@barroudjo
Copy link
Author

By the way I'm using angular 1.2.26.
On the other hand if I mix a nested property with a non-nested property in my expression it works as expected:

If I use

var expression = {
    length: 10,
    answerer : 
        email: 'adm'
    }
};

I get the empty array as expected.

If I use

var expression = {
    length: 20,
    answerer : 
        email: 'adm'
    }
};

it returns only the second element of array as expected.

So clearly the problem only exists when filtering on more than one nested property (probably if the nested properties are in the same parent property).

@gkalpak
Copy link
Member

gkalpak commented Oct 20, 2014

When specifying multiple nested properties, filterFilter matches using and implied OR.
E.g. assuming the following filter expression:

var expression = {
    answerer : {
        name : 'test',
        email: 'adm'
    }
};

it returns all items that match either answerer.name: 'test' or `answerer.email: 'adm'.

If it ie expected behaviour, I don't know...

@barroudjo
Copy link
Author

I don't think it is expected behavior, as I showed in the second post that
in other cases a logical AND is applied. Behavior has to be consistent.

On Mon, Oct 20, 2014 at 7:05 PM, Georgios Kalpakas <notifications@github.com

wrote:

When specifying multiple nested properties, filterFilter matches using
and implied OR.
E.g. assuming the following filter expression:

var expression = {
answerer : {
name : 'test',
email: 'adm'
}
};

it returns all items that match either answerer.name: 'test' or
`answerer.email: 'adm'.

If it ie expected behaviour, I don't know...


Reply to this email directly or view it on GitHub
#9698 (comment).

@barroudjo
Copy link
Author

For information I found a workaround, but it involves changing the comparator function:

compareForNestedFiltering = function (actual, expected) {
    function contains (actualVal, expectedVal) {
        return actualVal.toString().toLowerCase().indexOf(expectedVal.toString().trim().toLowerCase()) !== -1;
    }
    if(typeof expected !== 'object') return contains(actual, expected);
    var result = Object.keys(expected).every(function (key) {
        return contains(eval('actual.'+key), eval('expected.'+key));
    });
    return result;
};

and using it this way:

var filteredData = $filter('filter')(array, expression, compareForNestedFiltering)

gkalpak added a commit to gkalpak/angular.js that referenced this issue Oct 23, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Oct 23, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Oct 23, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698

Signed-off-by: Georgios Kalpakas <g.kalpakas@hotmail.com>
gkalpak added a commit to gkalpak/angular.js that referenced this issue Oct 23, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Oct 23, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Oct 23, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Oct 23, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Oct 23, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Oct 24, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Oct 25, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Oct 25, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Oct 25, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Oct 25, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
@nickL
Copy link

nickL commented Oct 26, 2014

+1. I'm also experiencing this on v1.2.6, specifically when I try and filter and array with multiple properties.

gkalpak added a commit to gkalpak/angular.js that referenced this issue Oct 27, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Oct 27, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Oct 28, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Oct 29, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Oct 31, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Nov 2, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Nov 4, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Nov 10, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Nov 11, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Nov 11, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Nov 12, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Nov 12, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Nov 13, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Nov 14, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Nov 18, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Nov 18, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Nov 18, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#7323
Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Nov 19, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#7323
Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Nov 21, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#7323
Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Nov 23, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#7323
Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Nov 24, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#7323
Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Nov 27, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#7323
Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Dec 1, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#7323
Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Dec 1, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#7323
Closes angular#9698
gkalpak added a commit to gkalpak/angular.js that referenced this issue Dec 2, 2014
Previously, trying to use a deep expression object (i.e. an object whose
properties can be objects themselves) did not work correctly.
This commit refactors `filterFilter`, making it simpler and adding support
for filtering collections of arbitrarily deep objects.

Closes angular#7323
Closes angular#9698
@gkalpak gkalpak closed this as completed in f7cf846 Dec 2, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants