I have an array of objects that I want to order dynamically, based on the value from the dropdown menu. This is what I still have on my list:
ng-repeat="item in filteredItems = (items | filter:searchInput | orderBy:canBeAnything)"
However, the problem is that sorting can be an attribute of an object or a computed value using a function. It should also be able to sort in descending order (optional).
I know that I can use the string for the canByAnything variable for orderBy, passing the attribute of an object, for example:
"-creationDate" // descending ordering on creation date "customer.lastname" // ascending ordering on customers last name
I also know that I can order the function:
orderBy:myCalculatedValueFunction
But I do not know and want to achieve:
- How to combine it so that I can use functions for sorting in combination with attributes / properties of objects. I mean one or the other, dynamically, based on what the user selected. Which can be an attribute or a computed value, neither descending nor ascending.
- How to sort the calculated value in descending order.
source share