Skip to content

Instantly share code, notes, and snippets.

@ksol
Last active August 1, 2016 01:59
Show Gist options
  • Save ksol/cf199f1f76ad8221a065 to your computer and use it in GitHub Desktop.
Save ksol/cf199f1f76ad8221a065 to your computer and use it in GitHub Desktop.
Ember.js: sorting with computed properties
export default Ember.Controller.extend({
posts: [], // Filled by real world data by the route
postsSorting: ['name'],
postsSortingDesc: ['name:desc'],
sortedPosts: Ember.computed.sort('posts', 'postsSorting'),
sortedPostsDesc: Ember.computed.sort('posts', 'postsSortingDesc'),
customSortedPost: Ember.computed.sort('posts', function(a, b) {
// return a negative when a < b, 0 when a = b, and a positive when a > b
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment