Add drop-down option to hide headers.
This commit is contained in:
@@ -6,6 +6,7 @@ var util = function() {
|
|||||||
<li class="write-op"><a data-action="deleteColumn" class="menuAction" href="JavaScript:void(0);">Delete this column</a></li> \
|
<li class="write-op"><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="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> \
|
<li><a data-action="sortDesc" class="menuAction" href="JavaScript:void(0);">Sort descending</a></li> \
|
||||||
|
<li><a data-action="hideColumn" class="menuAction" href="JavaScript:void(0);">Hide this column</a></li> \
|
||||||
'
|
'
|
||||||
, rowActions: '<li><a data-action="deleteRow" class="menuAction write-op" href="JavaScript:void(0);">Delete this row</a></li>'
|
, rowActions: '<li><a data-action="deleteRow" class="menuAction write-op" href="JavaScript:void(0);">Delete this row</a></li>'
|
||||||
, cellEditor: ' \
|
, cellEditor: ' \
|
||||||
|
|||||||
16
src/view.js
16
src/view.js
@@ -186,6 +186,7 @@ my.DataTable = Backbone.View.extend({
|
|||||||
this.model.currentDocuments.bind('reset', this.render);
|
this.model.currentDocuments.bind('reset', this.render);
|
||||||
this.model.currentDocuments.bind('remove', this.render);
|
this.model.currentDocuments.bind('remove', this.render);
|
||||||
this.state = {};
|
this.state = {};
|
||||||
|
this.hiddenHeaders = [];
|
||||||
},
|
},
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
@@ -229,6 +230,7 @@ my.DataTable = Backbone.View.extend({
|
|||||||
transform: function() { self.showTransformDialog('transform') },
|
transform: function() { self.showTransformDialog('transform') },
|
||||||
sortAsc: function() { self.setColumnSort('asc') },
|
sortAsc: function() { self.setColumnSort('asc') },
|
||||||
sortDesc: function() { self.setColumnSort('desc') },
|
sortDesc: function() { self.setColumnSort('desc') },
|
||||||
|
hideColumn: function() { self.hideColumn() },
|
||||||
// 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" },
|
||||||
@@ -297,6 +299,11 @@ my.DataTable = Backbone.View.extend({
|
|||||||
this.model.query(query);
|
this.model.query(query);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
hideColumn: function(order) {
|
||||||
|
this.hiddenHeaders.push(this.state.currentColumn);
|
||||||
|
this.render();
|
||||||
|
},
|
||||||
|
|
||||||
// ======================================================
|
// ======================================================
|
||||||
// Core Templating
|
// Core Templating
|
||||||
template: ' \
|
template: ' \
|
||||||
@@ -323,11 +330,15 @@ my.DataTable = Backbone.View.extend({
|
|||||||
|
|
||||||
toTemplateJSON: function() {
|
toTemplateJSON: function() {
|
||||||
var modelData = this.model.toJSON()
|
var modelData = this.model.toJSON()
|
||||||
modelData.notEmpty = ( modelData.headers.length > 0 )
|
modelData.notEmpty = ( this.headers.length > 0 )
|
||||||
|
modelData.headers = this.headers;
|
||||||
return modelData;
|
return modelData;
|
||||||
},
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
this.headers = _.filter(this.model.get('headers'), function(header) {
|
||||||
|
return _.indexOf(self.hiddenHeaders, header) == -1;
|
||||||
|
});
|
||||||
var htmls = $.mustache(this.template, this.toTemplateJSON());
|
var htmls = $.mustache(this.template, this.toTemplateJSON());
|
||||||
this.el.html(htmls);
|
this.el.html(htmls);
|
||||||
this.model.currentDocuments.forEach(function(doc) {
|
this.model.currentDocuments.forEach(function(doc) {
|
||||||
@@ -336,7 +347,7 @@ my.DataTable = Backbone.View.extend({
|
|||||||
var newView = new my.DataTableRow({
|
var newView = new my.DataTableRow({
|
||||||
model: doc,
|
model: doc,
|
||||||
el: tr,
|
el: tr,
|
||||||
headers: self.model.get('headers')
|
headers: self.headers,
|
||||||
});
|
});
|
||||||
newView.render();
|
newView.render();
|
||||||
});
|
});
|
||||||
@@ -355,6 +366,7 @@ my.DataTableRow = Backbone.View.extend({
|
|||||||
this.el = $(this.el);
|
this.el = $(this.el);
|
||||||
this.model.bind('change', this.render);
|
this.model.bind('change', this.render);
|
||||||
},
|
},
|
||||||
|
|
||||||
template: ' \
|
template: ' \
|
||||||
<td><a class="row-header-menu"></a></td> \
|
<td><a class="row-header-menu"></a></td> \
|
||||||
{{#cells}} \
|
{{#cells}} \
|
||||||
|
|||||||
Reference in New Issue
Block a user