Format for sort order on Ember.Array.sortBy


#1

I am trying to sort an array of Models with Array.sortBy() in descending order.

An example would be model.get('hasManyRelationship').sortBy('createdAt') Created at is an iso 8601 dateTIme

How can I control whether the out put of sortBy will be ascending or desceding? I tried sortBy.('createdAt:asc') but no luck.


#2

I think Ember.SortableMixin can still be used to overwrite your iso 8601 dateTime compare if necessary like this:


#3

I saw your stackoverflow question and provided an answer there. I’m just cross linking it here incase anyone has the same question.

Here is a twiddle I built that helps demonstrate your question on SO: http://ember-twiddle.com/60efa60e191fa9026774

Certainly there are other ways to do this, that’s just my take.

Also, FWIW, SortableMixin has been removed from Ember 2.x. Even though it’s available in the controller addon, it’ll likely become unsupported at some point in the near future.