On click of the ‘sort by age’, i am calling a function to fetch data from server and sort by age value. i do this after i done the fetching, but it result nothing and return all..
any one give a correct way to implement this?
my code:
this code in the view class,
sortByAge:function(){
this.collection.fetch() //fetching new collection
.done(function(data){ // once done i am passing data
var filterType = data.sort('age') // correct way need to sort.
that.collection.reset(filterType); // refreshing the collection
})
},
If before doing a
fetchyou’re already aware that you needcollectionto be sorted by some specificcolumn, from the docs, we can passajaxoptions to thefetch. Sofetchmight look like this:sort_byparameter will be available in theservercode being executed at the specifiedurlfor the collection, so you can return data from the server sorted bysort_bycolumn. And then may be listen toresetevent to do some work.And if you want to sort
collectionafter getting it on the client side may be you can look at these similar questions.