I have a list of users (six to be exact) in a collection with 'firstname', 'lastname' properties. Doing a fetch, the comparator below sorts them by 'firstname', and it works fine.
comparator : function (user) {
return user.get("firstname").toLowerCase();
}
But if I try to sort the collection later, by a different value i.e. 'lastname', it doesn't work. The order stays the same.
this.collection.sortBy(function(user) {
return user.get("lastname").toLowerCase();
});
What am i doing wrong?
Update
So the data returned from sortBy IS sorted but that doesn't help me really as my view is linked to the collection. If i reset the collection and add the sorted array back to the collection it's comparator does it's job and sorts it back into 'firstname' order.
var sorted = this.collection.sortBy(function(user) {
return user.get("lastname").toLowerCase();
});