Skip to content

Instantly share code, notes, and snippets.

@eimermusic
Created September 18, 2012 18:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eimermusic/3744939 to your computer and use it in GitHub Desktop.
Save eimermusic/3744939 to your computer and use it in GitHub Desktop.
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
Copy link

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