datatables and jsrender templates (previously jquery templates)

datatables and jsrender templates (previously jquery templates)

jegglestonjeggleston Posts: 2Questions: 0Answers: 0
edited October 2011 in General
Hi all,
I'm trying to use jquery templates with datatables. Essentially, I load the table data with a getJSON call, then populate the table with the template render. After the render, I call dataTable on the table. This works for the initial render, but when I sort, all data disappears.

Here's the code, in a nutshell
[code]


{{=data1}}
{{=data2}}
Hello




$(document).ready(function() {
/* Fetch data, and populate table. */
$.getJSON('/api/get_data', function(data) {
$("#tbody_id").html(
$("#tr_template").render(data)
);
} );
/* Apply dataTable. */
$('#table_id').dataTable();
} );
[/code]

Like I said, the table comes up fine initially. But, when I click one of the headers to sort, all the data is lost, and I get "No data available in table".
Any thoughts on what I'm doing wrong?

Thanks,
Joe

Replies

  • jegglestonjeggleston Posts: 2Questions: 0Answers: 0
    Never mind. Stupid mistake. I needed to apply dataTable in the getJSON() callback.
This discussion has been closed.