Auto re-initialize destroyed tables

Auto re-initialize destroyed tables

oktavoktav Posts: 1Questions: 0Answers: 0
edited October 2012 in General
Hi all,

First thing's first: Really great job with this project.

Now on to the painful bit:

I'm trying to re-initialize some datatables that have been destroyed after using [code]$("#table").replaceWith(data);[/code]

The "data" is html markup of a new table that comes from my server after a successful ajax request.

This is the bit that I use to initialize the table on load:

[code]
$(function() {
$("table[data-file-table]").dataTable({
"bPaginate": false,
"sDom": 'lrt'
});
});
[/code]

After I replace the HTML with the new data, I'd like the table to re-initialize automatically. I'm using RoR and I'm all about unobtrusive javascript and DRY approach. Is there a way similar to jQuery's $("el").on(event, el, fn) to keep an eye on the $("#table") element and re-initialize it as soon as it get's re-written?

Full code:

[code]

$(function() {
$("table[data-file-table]").dataTable({
"bPaginate": false,
"sDom": 'lrt'
});

$("#bigdiv").on("ajax:beforeSend", "a[data-refresher]", function(evt, xhr, settings) {
$(this).parent().loadingOverlay("show");
})
.on("ajax:success", "a[data-refresher]", function(evt, data, status, xhr) {
$(evt.target).parent().loadingOverlay("hide");
$(evt.target).parent().replaceWith(data);
});
});





...headers...



...rows...


[/code]

data-file-table can be more than 1.

Any suggestions?

Thanks
This discussion has been closed.