roseweixel
roseweixel

Reputation: 58

Sorting objects in Ember, Ember.SortableMixin sortProperties not working as expected

I'm new to Ember and recently followed the Ember "getting started" guide to build TodoMVC. Here it is in a jsbin.

Everything works, but now I'm trying to sort the todos by adding sortProperties to the TodosController:

Todos.TodosController = Ember.ArrayController.extend({
    sortProperties: ['title'],
    sortAscending: true,
    ...
});

And in the template, I have this:

{{#each todo in arrangedContent itemController="todo"}}
  ...
{{/each}}

Based on the Ember.SortableMixin documentation, what I'm doing seems to be reasonable but clearly I'm missing something.

Any help would be much appreciated!

Upvotes: 1

Views: 72

Answers (1)

roseweixel
roseweixel

Reputation: 58

Thanks to stevennunez, I understand what was missing - adding the following code fixed the problem:

Todos.TodosIndexController = Ember.ArrayController.extend({
    sortProperties: ['title'],
    sortAscending: true
});

Without this controller being defined, Ember by default created a "generic" Ember.ArrayController which was being used to render the todos/index template. Thus, the sortProperties placed in the TodosController had no effect.

Upvotes: 1

Related Questions