Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sortBy descending in Ember property

Tags:

ember.js

I'm sorting a collection that is a computed property in my model:

collection: function() {
  var entries = this.get('entries');
  return entries.sortBy('prop1', 'prop2');
}.property('[email protected]', '[email protected]')

But I can't figure out how to get it to sort descending. That should be easy, right?

Ember 1.13

like image 815
Eric Wilson Avatar asked Dec 17 '15 11:12

Eric Wilson


1 Answers

You can use Ember.computed.sort macro: http://emberjs.com/api/classes/Ember.computed.html#method_sort

Example:

entriesSorting: ['prop1:desc', 'prop2:desc'],
collection: Ember.computed.sort('entries', 'entriesSorting')

Unrelated, but relevant: the usage of Ember.computed over the .property prototype extention is recommended.

UPDATE: Here is a twiddle of this working: https://ember-twiddle.com/19ff8c56f1c13512bdc8

like image 92
miguelcobain Avatar answered Oct 31 '22 18:10

miguelcobain