1

OrderBy filter not work with 2nd parameter, it sort only by first parameter. Any ideas with how to solve this issue?

var found = $filter('orderBy')($scope.statusHistory, ['Id', { IsCreatedByMember: true}], true)[0];
semper fi
  • 727
  • 3
  • 17
  • 32

2 Answers2

1

It should use a function for expression, not an object:

var found = $filter('orderBy')($scope.statusHistory, [
  'Id',
  item => item.IsCreatedByMember
], true)[0];
dfsq
  • 191,768
  • 25
  • 236
  • 258
  • well it return an item where `IsCreatedByMember` equals `false` – semper fi Dec 06 '16 at 11:26
  • Of course. But the array is going to be sorted by `Id` first and then by `IsCreatedByMember` for items with same `Id`. If it's not what you are after, then you need to explain better. – dfsq Dec 06 '16 at 11:29
  • I need to get item, which sorted by descending by two parameters: `Id` and 2nd parameter `IsCreatedByMember` – semper fi Dec 06 '16 at 11:38
  • Yes, above code does exactly this: largest `Id` and `IsCreatedByMember` true. This is what you need? – dfsq Dec 06 '16 at 11:42
  • It returns the largest `Id` with `IsCreatedByMember` false – semper fi Dec 06 '16 at 11:52
  • Can you reproduce it in plunkr? Works for me: http://plnkr.co/edit/nQgitbRJ7rZN0V7DufJE?p=preview – dfsq Dec 06 '16 at 12:06
  • 1
    Then you don't want to sort by two fields. You need to filter by `IsCreatedByMember: true` and then sort by `Id`: http://plnkr.co/edit/j1lGzbG2aMGlYDGH76z9?p=preview – dfsq Dec 06 '16 at 12:39
0

You should try like this :

$filter('orderBy')( $scope.statusHistory, $scope.var1, $scope.var2);
Jigar7521
  • 1,549
  • 14
  • 27