At the moment I’m using JavaScript’s native sort() method to do my sorting in Ember, but in reality I know I should be using Ember’s own sorting, but unfortunately I have absolutely no idea how to use it.
I don’t want to waste people’s time in explaining it for me (unless you’re a masochist), but if anybody knows of a fabulous article on how to sort a collection of models in EmberJS, then it would be more than appreciated!
At the moment I have something like the following, where I’m just about the implement the sorting using the native sort again, but I stopped myself there because I want to learn the proper way.
SortOption: Ember.View.extend(
{
template: Ember.Handlebars.compile('<li><a href="javascript:void(0);">{{ option }}</a></li>'),
option: null,
click: function()
{
var rootView = this.nearestWithProperty('people');
var sortBy = this.get('option');
var sorted = rootView.get('people').orderBy('formalName');
rootView.set('people', sorted)
}
})
This pull request is for updated documentation regarding SortableMixin.
Sortable Mixin is now included in the ArrayController as of 0.9.8 release (I believe). All you need to do is define a sortProperties array on your controller and use the
arrangedContentproperty in your views. Here is an explanation from Ivan.