Support sorting by a given column; refs #34
This commit is contained in:
@@ -82,8 +82,7 @@ this.recline.Model = this.recline.Model || {};
|
|||||||
var numRows = queryObj.size;
|
var numRows = queryObj.size;
|
||||||
var start = queryObj.offset;
|
var start = queryObj.offset;
|
||||||
var dfd = $.Deferred();
|
var dfd = $.Deferred();
|
||||||
rows = model.backendConfig.data.rows;
|
results = model.backendConfig.data.rows;
|
||||||
var results = rows.slice(start, start+numRows);
|
|
||||||
// not complete sorting!
|
// not complete sorting!
|
||||||
_.each(queryObj.sort, function(item) {
|
_.each(queryObj.sort, function(item) {
|
||||||
results = _.sortBy(results, function(row) {
|
results = _.sortBy(results, function(row) {
|
||||||
@@ -91,6 +90,7 @@ this.recline.Model = this.recline.Model || {};
|
|||||||
return (item[1] == 'asc') ? _out : -1*_out;
|
return (item[1] == 'asc') ? _out : -1*_out;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
var results = results.slice(start, start+numRows);
|
||||||
dfd.resolve(results);
|
dfd.resolve(results);
|
||||||
return dfd.promise();
|
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 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
|
// This also illustrates the limitations of separating the Dataset and the Backend
|
||||||
query: function(queryObj) {
|
query: function(queryObj) {
|
||||||
this.actualQuery = queryObj || this.defaultQuery;
|
this.queryState = queryObj || this.defaultQuery;
|
||||||
this.actualQuery = _.extend({size: 100, offset: 0}, this.actualQuery);
|
this.queryState = _.extend({size: 100, offset: 0}, this.queryState);
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var backend = my.backends[this.backendConfig.type];
|
var backend = my.backends[this.backendConfig.type];
|
||||||
var dfd = $.Deferred();
|
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 docs = _.map(rows, function(row) {
|
||||||
var _doc = new my.Document(row);
|
var _doc = new my.Document(row);
|
||||||
_doc.backendConfig = self.backendConfig;
|
_doc.backendConfig = self.backendConfig;
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ var util = function() {
|
|||||||
, columnActions: ' \
|
, columnActions: ' \
|
||||||
<li><a data-action="bulkEdit" class="menuAction" href="JavaScript:void(0);">Transform...</a></li> \
|
<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="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>'
|
, rowActions: '<li><a data-action="deleteRow" class="menuAction" href="JavaScript:void(0);">Delete this row</a></li>'
|
||||||
, cellEditor: ' \
|
, cellEditor: ' \
|
||||||
|
|||||||
@@ -227,6 +227,8 @@ my.DataTable = Backbone.View.extend({
|
|||||||
var actions = {
|
var actions = {
|
||||||
bulkEdit: function() { self.showTransformColumnDialog('bulkEdit', {name: self.state.currentColumn}) },
|
bulkEdit: function() { self.showTransformColumnDialog('bulkEdit', {name: self.state.currentColumn}) },
|
||||||
transform: function() { self.showTransformDialog('transform') },
|
transform: function() { self.showTransformDialog('transform') },
|
||||||
|
sortAsc: function() { self.setColumnSort('asc') },
|
||||||
|
sortDesc: function() { self.setColumnSort('desc') },
|
||||||
// TODO: Delete or re-implement ...
|
// TODO: Delete or re-implement ...
|
||||||
csv: function() { window.location.href = app.csvUrl },
|
csv: function() { window.location.href = app.csvUrl },
|
||||||
json: function() { window.location.href = "_rewrite/api/json" },
|
json: function() { window.location.href = "_rewrite/api/json" },
|
||||||
@@ -290,6 +292,10 @@ my.DataTable = Backbone.View.extend({
|
|||||||
$('.dialog').draggable({ handle: '.dialog-header', cursor: 'move' });
|
$('.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
|
// Core Templating
|
||||||
|
|||||||
Reference in New Issue
Block a user