angular-filter
angular-filter copied to clipboard
Filter data in nested json
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 } } ];
@ashoumalik can you please provide some live example? (e.g: jsbin, fiddle, etc.. ) Thx.
thx for reply jsfiddle example http://jsfiddle.net/9376x133/5/
Please check my example
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
thanks i solved it using another way http://plnkr.co/edit/WosMmUBrEQxwl8q2vnzU?p=preview
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.