1

Prior to using Ember-Model sorting my ArrayController with sortProperties and sortAscending worked as expected. Lately I switched to Ember-Model and the sorting feature doesn't work anymore.

Code so far:

App.Movie = Ember.Model.extend({
  rating: Ember.attr(),
  title: Ember.attr(),
  watched: Ember.attr(),
  year: Ember.attr(),
});

App.MoviesIndexController = Ember.ArrayController.extend({
  sortProperties: null,
  sortAscending: null,

  actions: {
    sortByAttribute: function (attr) {
      if (this.get('sortProperties')) {
        if (this.get('sortProperties')[0] === attr) {
          this.toggleProperty('sortAscending');
        } else {
          this.set('sortProperties', [attr]);
        }
      } else {
        this.set('sortProperties', [attr]);
        this.set('sortAscending', true);
      }
    }
  }
});

<table>
  <thead>
    <tr>
      <th {{action "sortByAttribute" "year"}}>Year </th>
    </tr>
  </thead>
  ...
</table>

Any idea?

Thx

1

1 Answer 1

1

It looks like it works to me, here's a jsbin example

http://emberjs.jsbin.com/eKibapI/8/edit

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.