get a datatable rendering with fake data
This commit is contained in:
40
src/view.js
Normal file
40
src/view.js
Normal file
@@ -0,0 +1,40 @@
|
||||
this.recline = this.recline || {};
|
||||
|
||||
recline.DataTable = Backbone.View.extend({
|
||||
|
||||
tagName: "div",
|
||||
className: "data-table-container",
|
||||
|
||||
// template: TODO ???
|
||||
|
||||
events: {
|
||||
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
var that = this;
|
||||
this.model.fetch({
|
||||
success: function(collection, resp) {
|
||||
that.render()
|
||||
}
|
||||
})
|
||||
},
|
||||
toTemplateJSON: function() {
|
||||
var modelData = this.model.toJSON()
|
||||
modelData.rows = _.map(modelData.rows, function(row) {
|
||||
var cellData = _.map(modelData.headers, function(header) {
|
||||
return {header: header, value: row[header]}
|
||||
})
|
||||
return { id: 'xxx', cells: cellData }
|
||||
})
|
||||
modelData.notEmpty = ( modelData.headers.length > 0 )
|
||||
return modelData;
|
||||
},
|
||||
render: function() {
|
||||
var template = $( ".dataTableTemplate:first" ).html()
|
||||
, htmls = $.mustache(template, this.toTemplateJSON())
|
||||
;
|
||||
$(this.el).html(htmls);
|
||||
return this;
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user