I have few filters in view
<tr ng-repeat="x in list | filter:search| offset:currentPage*pageSize| limitTo:pageSize ">
In my project to achieve good result, i have to make this filtering in controller not in view
i know the basic syntax $filter('filter')('x','x')
but i don't know how to make chain of filters in controller, so everything will work as in my example from template.
I found some solution, now just with one filter, but should work with many ;)
$scope.data = data; //my geojson from factory// $scope.geojson = {}; //i have to make empty object to extend it scope later with data, it is solution i found for leaflet // $scope.geojson.data = []; $scope.FilteredGeojson = function() { var result = $scope.data; if ($scope.data) { result = $filter('limitTo')(result,10); $scope.geojson.data = result; console.log('success'); } return result; };
and i use this function in ng-repeat works fine, but i have to check it with few filters.
Filters can be applied to the result of another filter. This is called "chaining" and uses the following syntax: {{ expression | filter1 | filter2 | ... }} E.g. the markup {{ 1234 | number:2 }} formats the number 1234 with 2 decimal points using the number filter.
The chaining filters are used to perform the multiple filter operations within the single result. This chaining filters operation will be chained using the pipe (|) symbol.
You can load only a specific filter by appending the filter name with Filter . app. controller('MyController', function(uppercaseFilter) { // HELLO var text = uppercaseFilter('hello'); // Hello var text = uppercaseFilter('hello', true); });
In AngularJS, you can also inject the $filter service within the controller and can use it with the following syntax for the filter. Syntax: $filter("filter")(array, expression, compare, propertyKey) function myCtrl($scope, $filter) { $scope. finalResult = $filter("filter")( $scope.
You can just re-filter what you get returned from your first filter. So on and so forth.
var filtered; filtered = $filter('filter')($scope.list, {name: $scope.filterParams.nameSearch}); filtered = $filter('orderBy')(filtered, $scope.filterParams.order);
Below plunkr demonstrates the above.
http://plnkr.co/edit/Ej1O36aOrHoNdTMxH2vH?p=preview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With