Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tiny simple sort-action for Ember.js ArrayController content
App.UsersController = Ember.ArrayController.extend({
sortProperties: ['name'],
sortAscending: true,
reSort: function(sortBtnValue) {
var sortProperty = this.get('sortProperties')[0];
if (sortProperty == sortBtnValue) {
if (this.get('sortAscending')) {
this.set('sortAscending', false);
} else {
this.set('sortAscending', true);
}
}
this.set('sortProperties', [sortBtnValue]);
}
});
@notmessenger

This comment has been minimized.

Copy link

@notmessenger notmessenger commented Mar 28, 2013

Can use 'toggleProperty' as well:

App.UsersController = Ember.ArrayController.extend({
sortProperties: ['name'],
sortAscending: true,

reSort: function(sortBtnValue) {
var sortProperty = this.get('sortProperties')[0];
if (sortProperty == sortBtnValue) {
this.toggleProperty('sortAscending');
}
this.set('sortProperties', [sortBtnValue]);
}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment