diff --git a/src/backend.js b/src/backend.js index 581311ec..241280be 100644 --- a/src/backend.js +++ b/src/backend.js @@ -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(); } diff --git a/src/model.js b/src/model.js index 5ff36653..601e03a1 100644 --- a/src/model.js +++ b/src/model.js @@ -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; diff --git a/src/util.js b/src/util.js index 97e5c82d..c2883cf6 100644 --- a/src/util.js +++ b/src/util.js @@ -4,6 +4,8 @@ var util = function() { , columnActions: ' \
  • Transform...
  • \
  • Delete this column
  • \ +
  • Sort ascending
  • \ +
  • Sort descending
  • \ ' , rowActions: '
  • Delete this row
  • ' , cellEditor: ' \ diff --git a/src/view.js b/src/view.js index d1850d7d..8cf9cce0 100644 --- a/src/view.js +++ b/src/view.js @@ -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