I have a table list with three columns. There are the possibility to sort all columns up an down. When you click on the -Tag then the list will sorted but I'm getting the error message:
Error: $injector:unpr Unknown Provider
Unknown provider: orderbyFilterProvider <-
Here is the Ctrl:
var orderby = $filter('orderby');
$scope.sortType = '-maxAge';
$scope.sortReverse = false;
$scope.order = function (sortType, sortReverse) {
$scope.nameslist = orderby($scope.nameslist, sortType, sortReverse);
};
The view (header):
...
<th>
<a href="" ng-click="sortReverse = !sortReverse; order('fname',reverse)">
Firstame
<span ng-show="sortType=='fname' && !sortReverse" class="glyphicon glyphicon-triangle-bottom"></span>
<span ng-show="sortType=='fname' && sortReverse" class="glyphicon glyphicon-triangle-top"></span>
</a>
</th>
...
The view (table list):
<tr ng-repeat="item in filteredNames = (nameslist | orderBy: sortType:sortReverse)" class="show-cursor">
<td>{{ item.fname }}</td>
...
</tr>
I don't know where is the problem?!
Definition and Usage The orderBy filter allows us to sort an array. By default, strings are sorted alphabetically, and numbers are sorted numerically.
To sort in descending order, set it as true . You can also use + to sort the data in an ascending and – the data in descending order also . Here with the filters in Angular JS, instead of displaying the various rows, we will be sorting it by ascending and descending order .
AngularJS orderBy filter allows sorting of data in a collection. It supports both, ascending and descending order. The "+" operator is used to order the data in ascending order and thde "-" operator is used to order the data in descending order.
You need to use camel case its orderBy not orderby in your controller
var orderBy = $filter('orderBy');
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