Ember.js: sorting with computed properties

Posted by Kevin Soltysiak on June 2, 2015 Topics: ember.js

Ember.js has recently deprecated its ObjectController, since the automatic "proxying" of properties to the model is now an anti-pattern (and a source of confusion for beginners).

While ArrayController is not yet deprecated, you should stay away from it for the same reason. Features specific to it such as itemControllers can be achieved by using components instead.

You could also sort arrangedContent quickly with sortProperties or sortFunction. This can be replaced with a computed property, which has the advantage of being usable from almost everywhere, and not just ArrayController subclasses.

Ember.computed.sort (API reference here) allows you to either supply a list of sorting properties or a function. The usage is pretty straightforward:

And that's how you sort properly in Ember.js.