I am trying to filter a list with multiple filters + using a special filter function.
The original working jsfiddle example is http://jsfiddle.net/ed9A2/1/ , but now I want to change the way the age is filtered.
I want to add a custom filter so that age is filtered based on the two input values min_age and max_age , (between the ages).
After viewing the document. I found people with similar questions, and Mark Rajcok user answers http://docs.angularjs.org/api/ng.filter:filter#comment-648569667 , which looks good and should work. But I had a problem with its application in my codes, this is mainly due to the fact that I have several different filters.
Im very new to AngularJS :(
My trial and broken fiddle is here http://jsfiddle.net/ed9A2/20/
Copy my my work codes here
View
<div ng-app ng-controller="MainController"> <table class="fancyTable"> <tr> <th>Player id</th> <th>Player name</th> <th>Age</th> </tr> <tr> <td><input ng-model="player_id" /></td> <td><input ng-model="player_name" /></td> <td> Min Age:<input ng-model="min_age" /> Max Age:<input ng-model="max_age" /> </td> </tr> <tr ng-repeat="player in players | filter:{id: player_id, name:player_name, age:ageFilter}"> <td>{{player.id}}</td> <td>{{player.name}}</td> <td>{{player.age}}</td> </tr> </table>
controller
function MainController($scope) { $scope.player_id = ""; $scope.player_name = ""; $scope.player_age = ""; $scope.min_age = 0; $scope.max_age = 999999999; $scope.ageFilter = function(player) { return ( player > $scope.min_age && player.age < $scope.max_age); } $scope.players = [ {"name": "Rod Laver", "id": "rod", "date": "1938/8/9", "imageUrl": "img/rod-laver.gif", "age": 75}, {"name": "Boris Becker", "id": "borix", "date": "1967/11/22", "imageUrl": "img/boris-becker.gif", "age": 45}, {"name": "John McEnroe", "id": "mcenroe", "date": "1959/2/16", "imageUrl": "img/john-mc-enroe.gif", "age": 54}, {"name": "Rafa Nadal", "id": "nadal", "date": "1986/5/24", "imageUrl": "img/ndl.jpg", "age": 27} ] }
javascript angularjs angularjs-ng-repeat
cjmling Sep 13 '13 at 17:30 2013-09-13 17:30
source share