Support sorting by a given column; refs #34
This commit is contained in:
parent
b96de6c34f
commit
5fc4fa9626
@ -82,8 +82,7 @@ this.recline.Model = this.recline.Model || {};
|
||||
var numRows = queryObj.size;
|
||||
var start = queryObj.offset;
|
||||
var dfd = $.Deferred();
|
||||
rows = model.backendConfig.data.rows;
|
||||
var results = rows.slice(start, start+numRows);
|
||||
results = model.backendConfig.data.rows;
|
||||
// not complete sorting!
|
||||
_.each(queryObj.sort, function(item) {
|
||||
results = _.sortBy(results, function(row) {
|
||||
@ -91,6 +90,7 @@ this.recline.Model = this.recline.Model || {};
|
||||
return (item[1] == 'asc') ? _out : -1*_out;
|
||||
});
|
||||
});
|
||||
var results = results.slice(start, start+numRows);
|
||||
dfd.resolve(results);
|
||||
return dfd.promise();
|
||||
}
|
||||
|
||||
@ -35,12 +35,13 @@ this.recline.Model = this.recline.Model || {};
|
||||
// this does not fit very well with Backbone setup. Backbone really expects you to know the ids of objects your are fetching (which you do in classic RESTful ajax-y world). But this paradigm does not fill well with data set up we have here.
|
||||
// This also illustrates the limitations of separating the Dataset and the Backend
|
||||
query: function(queryObj) {
|
||||
this.actualQuery = queryObj || this.defaultQuery;
|
||||
this.actualQuery = _.extend({size: 100, offset: 0}, this.actualQuery);
|
||||
this.queryState = queryObj || this.defaultQuery;
|
||||
this.queryState = _.extend({size: 100, offset: 0}, this.queryState);
|
||||
|
||||
var self = this;
|
||||
var backend = my.backends[this.backendConfig.type];
|
||||
var dfd = $.Deferred();
|
||||
backend.query(this, this.actualQuery).then(function(rows) {
|
||||
backend.query(this, this.queryState).then(function(rows) {
|
||||
var docs = _.map(rows, function(row) {
|
||||
var _doc = new my.Document(row);
|
||||
_doc.backendConfig = self.backendConfig;
|
||||
|
||||
@ -4,6 +4,8 @@ var util = function() {
|
||||
, columnActions: ' \
|
||||
<li><a data-action="bulkEdit" class="menuAction" href="JavaScript:void(0);">Transform...</a></li> \
|
||||
<li><a data-action="deleteColumn" class="menuAction" href="JavaScript:void(0);">Delete this column</a></li> \
|
||||
<li><a data-action="sortAsc" class="menuAction" href="JavaScript:void(0);">Sort ascending</a></li> \
|
||||
<li><a data-action="sortDesc" class="menuAction" href="JavaScript:void(0);">Sort descending</a></li> \
|
||||
'
|
||||
, rowActions: '<li><a data-action="deleteRow" class="menuAction" href="JavaScript:void(0);">Delete this row</a></li>'
|
||||
, cellEditor: ' \
|
||||
|
||||
@ -227,6 +227,8 @@ my.DataTable = Backbone.View.extend({
|
||||
var actions = {
|
||||
bulkEdit: function() { self.showTransformColumnDialog('bulkEdit', {name: self.state.currentColumn}) },
|
||||
transform: function() { self.showTransformDialog('transform') },
|
||||
sortAsc: function() { self.setColumnSort('asc') },
|
||||
sortDesc: function() { self.setColumnSort('desc') },
|
||||
// TODO: Delete or re-implement ...
|
||||
csv: function() { window.location.href = app.csvUrl },
|
||||
json: function() { window.location.href = "_rewrite/api/json" },
|
||||
@ -290,6 +292,10 @@ my.DataTable = Backbone.View.extend({
|
||||
$('.dialog').draggable({ handle: '.dialog-header', cursor: 'move' });
|
||||
},
|
||||
|
||||
setColumnSort: function(order) {
|
||||
var query = _.extend(this.model.queryState, {sort: [[this.state.currentColumn, order]]});
|
||||
this.model.query(query);
|
||||
},
|
||||
|
||||
// ======================================================
|
||||
// Core Templating
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user