i am trying to use datatables in the template rendered by underscorejs using backbone. My template code is this:
<script type="text/template" id="ledgerListing">
<table>
<thead>
<tr><th>Name</th><th>Email</th><th>Phone</th><th>address</th></tr>
</thead>
<tbody>
<tr><td>mrinal</td><td>mrinal</td><td>mrinal</td><td>mrinal</td></tr>
</tbody></table>
</script>
And in one of my views i do a function like this:
ledgerTemplate: _.template($("#ledgerListing").html()),
loadLedger: function(){
this.container.html(this.ledgerTemplate());
}
On top of the page i initialize datatables like this:
$(document).ready(function() {
$('table').dataTable();
} );
The table gets rendered but the datatable plugin is not applied. I guess anything within the script tags are not hooked up to DOM during pageload. If this is the case, whats the way to apply datatables on a template rendered by underscorejs. Any suggestions…
Ok it worked for me. I am a stupid really 🙂
just needed to initialize datatable after the template is populated like this: