I am trying to sort my collection using .sort()
however I can only seem to sort the collection in an ascending manner, by code for the collection is like this,
var ProjectCollection = Backbone.Collection.extend({
url: '/projects',
model: app.Project,
sort_key: "finish_date",
comparator: function (item) {
return item.get(this.sort_key);
},
sortByField: function(fieldName, orderType) {
console.log(fieldName, orderType);
this.sort_key = fieldName;
if(orderType == "acsending") {
this.sort(function(a, b){return a-b});
} else if(orderType == "descending") {
this.sort(function(a, b){return b-a});
}
}
});
The sortByField function gets fired from the view on a select menu change, and it fires this function,
sortCollection: function(e) {
this.collection.sortByField($('.sort').val(), $('.order').val());
console.log(this.collection);
}
Why would I not be able to sort in a descending order? The parameters that get sent to the collections function are correct, and the if and if else are run correctly based on those params.