Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember - sort array by multiple properties in multiple directions

I need to sort a collection of Ember Models by multiple properties, and not necessary in the same direction/order. I.e. I need to sort by property a in ascending order and by property b in descending. Is there a way to achieve this?

Update

I tried setting the sortAscending property to a array, but it is not working. After looking into the source it seems that this functionality is not supported out of the box(yet).

like image 349
Shimon Rachlenko Avatar asked Feb 21 '13 09:02

Shimon Rachlenko


1 Answers

In your ArrayController:

sortProperties: ["propA:asc", "propB:desc"]
sortedModel: Ember.computed.sort("model", "sortProperties");

Then reference sortedModel in your template's #each handler.

like image 161
neverfox Avatar answered Oct 17 '22 06:10

neverfox