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

Filter data in nested json

Open ashmohd opened this issue 10 years ago • 6 comments

Filter by working fine if- there is a single item 0n corresponding users filterBy: ['users.strict']: 'john'

But filterBy not working in following json if users have multiple items $scope.data = [ { id: 1, users: [{ first_name: 'Rob', last_name: 'John', mobile: 4444 },{ first_name: 'Robin', last_name: 'Johny', mobile: 44447 },{ first_name: 'Robot', last_name: 'Johno', mobile: 44044 }] }, { id: 2, users: [{ first_name: 'Johni', last_name: 'Wayno', mobile: 3333 },{ first_name: 'John', last_name: 'Wayne', mobile: 3333 }] }, { id: 3, users: [{ first_name: 'Rob1', last_name: 'Johansson1', mobile: 2222 },{ first_name: 'Rob2', last_name: 'Johansson2', mobile: 29222 } }, { id: 4, users: { first_name: 'Mike', last_name: 'Terry', mobile: 1111 } } ];

ashmohd avatar Feb 01 '15 13:02 ashmohd

@ashoumalik can you please provide some live example? (e.g: jsbin, fiddle, etc.. ) Thx.

a8m avatar Feb 01 '15 13:02 a8m

thx for reply jsfiddle example http://jsfiddle.net/9376x133/5/

ashmohd avatar Feb 01 '15 15:02 ashmohd

Please check my example

ashmohd avatar Feb 01 '15 16:02 ashmohd

Because it's not 'customer.name' but 'customer[x].name'. You can already see it in your html, it doesn't recognize what is 'customer.name'

You will probably need to insert another ng-repeat inside your first, like this:

<div ng-app="myApp">
    <div ng-controller="VersionFilterCtrl">
        <input type='text' name='name' ng-model='search.customer.name'>
        <input type='text' name='name' ng-model='search.customer.id'>
        <div ng-repeat="order in orders">
            <ul>
                <li ng-repeat="customer in order.customer | filterBy:['name']:search.customer.name">{{customer.id}} - {{ customer.name }}</li>
            </ul>
        </div>
    </div>
</div>

Do you have any suggestion @a8m

mallowigi avatar Feb 02 '15 07:02 mallowigi

thanks i solved it using another way http://plnkr.co/edit/WosMmUBrEQxwl8q2vnzU?p=preview

ashmohd avatar Feb 10 '15 06:02 ashmohd

hi,

is there a way to group by nested array too?

scope data looks like:

[ {id: 1, name: 'max', things: [ {type: 'house}, {type: 'car'}]}, {id: 2, name: 'sam', things: [ {type: 'mobilephone'}, {type: 'car'}]}, {id: 3, name: 'james', things: [ {type: 'mobilephone'}, {type: 'computer'}]} ]

how can i group the data by type?

thanks.

3h3c avatar Apr 14 '15 15:04 3h3c