Skip to content

Instantly share code, notes, and snippets.

@rmw
Created December 10, 2011 07:45
Show Gist options
  • Save rmw/1454792 to your computer and use it in GitHub Desktop.
Save rmw/1454792 to your computer and use it in GitHub Desktop.
Backbone.js secondary sort order with collection comparator example
App.Collections.Notes = Backbone.Collection.extend({
model: Note,
url: '/notes.json',
comparator : function(note) {
//ordering by status (alphabetically asc) and id (numeric desc)
var stat = note.get('status');
var note_id = note.get('id');
var sort_order = (stat.charCodeAt(0) * 100000) - note_id;
return sort_order;
}
});
@rmw
Copy link
Author

rmw commented Dec 10, 2011

Is there a better way to do this?

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