I have template in html as:
<script type="text/template" id="table-template">
<div id="table-body"></div>
</script>
My backbone view look like this:
var app = app || {};
$(function ($) {
'use strict';
info = [
{
"id": 1,
"Age": 70,
"salary": 700000,
"name": "Mike",
},
{
"id": 2,
"Age": 18,
"salary": 30000,
"name": "Mike",
},
];
app.infoView = Backbone.View.extend({
initialize: function () {
console.log('initialize');
},
drawinfoTable: function () {
console.log('create datatable');
$('#test').dataTable({
"aaData": groupdata,
"aoColumns": [
{ "mDataProp": "id" },
{ "mDataProp": "age" },
{ "mDataProp": "sal" },
{ "mDataProp": "active" },
{ "mDataProp": "name" }
]
});
}
render: function () {
console.log('render');
var template = _.template($("#-template").html(), {});
this.$el.html(template);
}
});
});
Actually with above JSON data, I want to create datatable with column name id, sal, active & sal. I am using jquery.dataTables.min.js to create datatable. Then, I want to insert that datatable inside "table-body" div, which is present inside "table-template". Your help will be greatly appreciated.