Merge branch 'master' of github.com:okfn/recline
This commit is contained in:
@@ -135,35 +135,23 @@ my.SlickGrid = Backbone.View.extend({
|
|||||||
this.grid = new Slick.Grid(this.el, data, visibleColumns, options);
|
this.grid = new Slick.Grid(this.el, data, visibleColumns, options);
|
||||||
|
|
||||||
// Column sorting
|
// Column sorting
|
||||||
var gridSorter = function(field, ascending, grid, data){
|
|
||||||
|
|
||||||
data.sort(function(a, b){
|
|
||||||
var result =
|
|
||||||
a[field] > b[field] ? 1 :
|
|
||||||
a[field] < b[field] ? -1 :
|
|
||||||
0
|
|
||||||
;
|
|
||||||
return ascending ? result : -result;
|
|
||||||
});
|
|
||||||
|
|
||||||
grid.setData(data);
|
|
||||||
grid.updateRowCount();
|
|
||||||
grid.render();
|
|
||||||
}
|
|
||||||
|
|
||||||
var sortInfo = this.state.get('columnsSort');
|
var sortInfo = this.state.get('columnsSort');
|
||||||
if (sortInfo){
|
if (sortInfo.column){
|
||||||
var sortAsc = !(sortInfo['direction'] == 'desc');
|
var sortAsc = !(sortInfo.order == 'desc');
|
||||||
gridSorter(sortInfo.column, sortAsc, self.grid, data);
|
|
||||||
this.grid.setSortColumn(sortInfo.column, sortAsc);
|
this.grid.setSortColumn(sortInfo.column, sortAsc);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.grid.onSort.subscribe(function(e, args){
|
this.grid.onSort.subscribe(function(e, args){
|
||||||
gridSorter(args.sortCol.field,args.sortAsc,self.grid,data);
|
var order = (args.sortAsc) ? 'asc':'desc';
|
||||||
self.state.set({columnsSort:{
|
self.state.set({columnsSort:{
|
||||||
column:args.sortCol,
|
column:args.sortCol.field,
|
||||||
direction: (args.sortAsc) ? 'asc':'desc'
|
order: order
|
||||||
}});
|
}});
|
||||||
|
|
||||||
|
var sort = [{}];
|
||||||
|
sort[0][args.sortCol.field] = {order: order};
|
||||||
|
self.model.query({sort: sort});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.grid.onColumnsReordered.subscribe(function(e, args){
|
this.grid.onColumnsReordered.subscribe(function(e, args){
|
||||||
|
|||||||
Reference in New Issue
Block a user