Getting issue while destroy/Reinitialize Individual search Data table
Getting issue while destroy/Reinitialize Individual search Data table
On a button click want to fetch fresh updated data in data table , when reinitialize table it will become multiple headers
Note i am using Individual search in data table .
Kindly find my below code for the same:
var table;
if ( $.fn.dataTable.isDataTable('#CompletedTID') ) {
table = $('#CompletedTID').DataTable();
table.destroy();
}
$('#CompletedTID thead tr').clone(true).appendTo('#CompletedTID thead');
$('#CompletedTID thead tr:eq(1) th').each(function (i) {
var title = $(this).text();
$(this).html('<input type="text" placeholder="' + title + '" />');
$('input', this).on('keyup change', function () {
if (table.column(i).search() !== this.value) {
table
.column(i)
.search(this.value)
.draw();
}
});
});
table = $('#CompletedTID').DataTable({
fixedHeader: true,
destroy:true
});
Answers
var table;
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
You are executing this each time you create reinitialize the Datatable:
So it will append another
thead
to the table. Datatables doesn't know about this header, since you are adding it, and won't remove it when usingdestroy()
. Move this statement to a place where it is executed only once.Kevin