Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting filter 'orderBy' doesn't work in AngularJS

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?!

like image 734
yuro Avatar asked Jul 03 '15 12:07

yuro


People also ask

What is orderBy filter in AngularJS?

Definition and Usage The orderBy filter allows us to sort an array. By default, strings are sorted alphabetically, and numbers are sorted numerically.

How to use sorting in AngularJS?

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 .

How to sort in descending order in AngularJS?

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.


1 Answers

You need to use camel case its orderBy not orderby in your controller

var orderBy = $filter('orderBy');
like image 116
mikeswright49 Avatar answered Oct 04 '22 09:10

mikeswright49