[view][s]: (refs #14) switched DataTable view to render using DataTableRow view (rendering now in pure js!).
This commit is contained in:
38
src/view.js
38
src/view.js
@@ -206,7 +206,7 @@ my.DataTable = Backbone.View.extend({
|
|||||||
// Core Templating
|
// Core Templating
|
||||||
template: ' \
|
template: ' \
|
||||||
<table class="data-table" cellspacing="0"> \
|
<table class="data-table" cellspacing="0"> \
|
||||||
<tbody> \
|
<thead> \
|
||||||
<tr> \
|
<tr> \
|
||||||
{{#notEmpty}}<td class="column-header"></td>{{/notEmpty}} \
|
{{#notEmpty}}<td class="column-header"></td>{{/notEmpty}} \
|
||||||
{{#headers}} \
|
{{#headers}} \
|
||||||
@@ -219,39 +219,32 @@ my.DataTable = Backbone.View.extend({
|
|||||||
</td> \
|
</td> \
|
||||||
{{/headers}} \
|
{{/headers}} \
|
||||||
</tr> \
|
</tr> \
|
||||||
{{#rows}} \
|
</thead> \
|
||||||
<tr data-id="{{id}}"> \
|
<tbody></tbody> \
|
||||||
<td><a class="row-header-menu"></a></td> \
|
|
||||||
{{#cells}} \
|
|
||||||
<td data-header="{{header}}"> \
|
|
||||||
<div class="data-table-cell-content"> \
|
|
||||||
<a href="javascript:{}" class="data-table-cell-edit" title="Edit this cell"> </a> \
|
|
||||||
<div class="data-table-cell-value">{{value}}</div> \
|
|
||||||
</div> \
|
|
||||||
</td> \
|
|
||||||
{{/cells}} \
|
|
||||||
</tr> \
|
|
||||||
{{/rows}} \
|
|
||||||
</tbody> \
|
|
||||||
</table> \
|
</table> \
|
||||||
',
|
',
|
||||||
|
|
||||||
toTemplateJSON: function() {
|
toTemplateJSON: function() {
|
||||||
var modelData = this.model.toJSON()
|
var modelData = this.model.toJSON()
|
||||||
modelData.rows = _.map(this._currentDocuments.models, function(doc) {
|
|
||||||
var cellData = _.map(modelData.headers, function(header) {
|
|
||||||
return {header: header, value: doc.get(header)}
|
|
||||||
})
|
|
||||||
return { id: 'xxx', cells: cellData }
|
|
||||||
})
|
|
||||||
modelData.notEmpty = ( modelData.headers.length > 0 )
|
modelData.notEmpty = ( modelData.headers.length > 0 )
|
||||||
return modelData;
|
return modelData;
|
||||||
},
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
|
var self = this;
|
||||||
var template = $( ".dataTableTemplate:first" ).html()
|
var template = $( ".dataTableTemplate:first" ).html()
|
||||||
, htmls = $.mustache(template, this.toTemplateJSON())
|
, htmls = $.mustache(template, this.toTemplateJSON())
|
||||||
;
|
;
|
||||||
$(this.el).html(htmls);
|
this.el.html(htmls);
|
||||||
|
this._currentDocuments.forEach(function(doc) {
|
||||||
|
var tr = $('<tr />');
|
||||||
|
self.el.find('tbody').append(tr);
|
||||||
|
var newView = new my.DataTableRow({
|
||||||
|
model: doc,
|
||||||
|
el: tr,
|
||||||
|
headers: self.model.get('headers')
|
||||||
|
});
|
||||||
|
newView.render();
|
||||||
|
});
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -264,6 +257,7 @@ my.DataTableRow = Backbone.View.extend({
|
|||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
this._headers = options.headers;
|
this._headers = options.headers;
|
||||||
this.el = $(this.el);
|
this.el = $(this.el);
|
||||||
|
this.model.bind('change', this.render);
|
||||||
},
|
},
|
||||||
template: ' \
|
template: ' \
|
||||||
<td><a class="row-header-menu"></a></td> \
|
<td><a class="row-header-menu"></a></td> \
|
||||||
|
|||||||
Reference in New Issue
Block a user