I am trying to filter json data with various options(like with slider and with some radio buttons). I am failing to filter out with radio buttons as exactly I am not getting any idea how to filter with those ?
With radio button options: if I click: "First Val: >=50", then the table data should be filtered/displayed only for which whose "Value 1" is greater than or equal to 50(>=50) and Similarly for second option: if I click: "Second Val: >=100", then the table data should be filtered/displayed only for which whose "Value 2" is greater than or equal to 100(>=100), but I am unable to get it.
Anyone can help me about it please ? Thanks in advance. Created Fiddle.
html:
<body ng-controller='TestCtrl'>
<slider floor="0" ceiling="50" ng-model-low="low_marks" ng-model-high="high_marks"></slider>
low_marks: <strong>{{low_marks}}</strong>
high_marks: <strong>{{high_marks}}</strong>
<hr>
<label>>=50<input type="radio" name="value1" ng-model="type" value='value1' ></label><br><br>
<label>>=100<input type="radio" name="value2" ng-model="type" value='value2' ></label><br><br>
<table border="1">
<thead>
<th>Name</th>
<th>Low Marks</th>
<th>High Marks</th>
<th>Value 1</th>
<th>Value 2</th>
</thead>
<tbody>
<tr ng-repeat='item in items|filter:marksrange'>
<td>{{item.name}}</td>
<td>{{item['minmarks']}}</td>
<td>{{item['maxmarks']}}</td>
<td>{{item.value1}}</td>
<td>{{item.value2}}</td>
</tr>
</tbody>
</table>
</body>
js:
var app = angular.module('marks', ['uiSlider']);
app.controller('TestCtrl', function ($scope){
$scope.items = [{name: "name1", "minmarks": "35",
"maxmarks": "100", "value1": "50", "value2": "100"},
{name: "name2", "minmarks": "50",
"maxmarks": "80", "value1": "100", "value2": "150"},
{name: "name3", "minmarks": "70",
"maxmarks": "90", "value1": "25", "value2": "50"}];
$scope.low_marks = 0;
$scope.high_marks = 100;
$scope.marksrange = function(item) {
return (parseInt(item['minmarks']) >= $scope.low_marks && parseInt(item['maxmarks']) <= $scope.high_marks);
};
});
$scope.typein your filter function