User1899289003 User1899289003 - 1 month ago 13
Javascript Question

DataTable not refresh information

I'm using jQuery DataTables plugin with a dynamic html table, first of all, I draw my table with an ajax call, for that I use something like this:

EDIT:

Draw funcion ajax success
success: function (data) {
var aRC = JSON.parse(data.d);
var lines = "";
for (var i = 0; i < aRC.length; i++) {
var id = aRC[i].Id;
var num = id;
var rev = aRC[i].Campo;
lines += '<tr id="P' + num + '" data-id="' + num + '">';
lines += '<td>' + num + '</td>';
lines += '<td id="P' + num + '-1">' + rev + '</td>';
lines += '<td class="text-center">';
lines += ' <span class="btn btn-success btn-xs glyphicon glyphicon-edit" data-id="' + num + '"></span>';
lines += ' <span class="btn btn-danger btn-xs glyphicon glyphicon-remove" data-id="' + num + '"></span>';
lines += ' </td>';
lines += '</tr>';
}
$('#TableTBodyTag').html(lines);
$('#TableId').dataTable({
aLengthMenu: [
[10, 25, 50, 100, -1],
[10, 25, 50, 100, "All"]
],
"bDestroy": true,
iDisplayLength: 10,
});
}
});


Update Function ajax success

success: function (data) { correctamente
bootbox.alert(data.d);
window.Fam.reset();
Draw(); //Above function
}


When I execute my update function everything it's fine, but my datatable is not refreshed I can't see the change until I reload the page (F5). I call
Draw function
on document ready and in my update function.

I can't change the way of table is created, so how can I solve this issue?

Answer

This is what I did when I was using DT, modified to use your vars:

success: function (data) {   correctamente
    bootbox.alert(data.d);
    window.Fam.reset();
    $('#TableId').dataTable().fnDestroy();
    $('#TableTBodyTag').html("");
    Draw(); //Above function
}

Best of luck!