0

I am trying to group by a set of items inside an array in reverse order. I cant figure out what I need. Any help will be appreciate it. I have tried orderby with the minus with no luck.

This is my code

It groups by Year and Month ascending order 2016, 2015. What I want is to display them in descending order 2014, 2015, 2016

$scope.Reports = 
[
{ Id: 1, Name: 'Report One', Year: 2016, Month: 5 },
{ Id: 2, Name: 'Report Core', Year: 2016, Month: 5 },
{ Id: 3, Name: 'Report Alpha', Year: 2016, Month: 3 },
{ Id: 4, Name: 'Report Moon', Year: 2015, Month: 5 },
{ Id: 5, Name: 'Report Sky', Year: 2015, Month: 2 }
];

<body>
<div ng-controller="MainController"> 
<ul ng-repeat="(key, value) in Reports | groupBy: 'Year'">
{{ key }}
<ul ng-repeat="(key1, value1) in value | groupBy: 'Month'">
O{{key1}} 
<li ng-repeat="p in value1">
{{p.Name }} 
</li>
</ul>
</ul>
</div>
</body>
Gilberto Quintero
  • 397
  • 1
  • 6
  • 18
  • What problems did you have with a negative orderby? Also, it [looks](https://docs.angularjs.org/api/ng/filter/orderBy) like you can tack on `:true` after the orderby to do a reverse. – Corey Ogburn Apr 09 '16 at 02:31
  • It doesnt work, here is my JS BIN with the orderby http://jsbin.com/ripolu/edit?html,js,output – Gilberto Quintero Apr 09 '16 at 02:57
  • You can't `orderBy:true`. You need to put the field you want to order by such as `orderBy:'Year'` or if you want to sort the other direction `orderBy:'-Year'` or `orderBy:'Year':true`. – Corey Ogburn Apr 09 '16 at 03:00
  • Added orderBy:'Year':true, still having issues, not working – Gilberto Quintero Apr 09 '16 at 03:06
  • {{ orderBy_expression | orderBy : expression : reverse}} have you tried reverse or | - Year – nCore Apr 09 '16 at 03:39

0 Answers0