Sorting
We also need to be able to set different sorting ways and it has to happen on server-side. This is also covered by this library by using fetchSortedBy method. It has the pair function similar to filtrate to reset sorting called resetSort.
A simple example of using the fetchSortedBy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
var SortedView = Marionette.CollectionView.extend({ ui: { select: 'select' }, events: { 'change @ui.select': 'change' }, change: function (ev) { var self = this; if (ev.currentTarget.value.length > 0) { self.collection.fetchSortedBy(ev.currentTarget.value); } else { self.collection.resetSort(); } } }); |
That’s it. The code can be found on my github: https://github.com/charlesnagy/backbone-tastypie
Recent comments