Checkboxes not visible in DataTable second time.
Checkboxes not visible in DataTable second time.
Hi,
i am binding the table using callback by using UpdatePanel.
Once my button click code behind runs completely, i call a script on aspx page using Scriptmanager.ClientScriptblock()...
and in the called java script function i append rows to DataTable.
On first load it adds the checkboxes as first column. but in second time they are not visible and will be shown only when i sort the table. Can some please help.
i am appneding rows to tbody as follows
$("#bodyListLetter tr").remove(); // first removing tr and then add.
$('#bodyListLetter').append(Rows);
Table initialisation code.
if ($.fn.dataTable.isDataTable('#example2')) {
table = $('#example2').DataTable();
}
else {
$('#example2').DataTable({
"searching": false,
"retrieve": false,
"paging": false,
"ordering": true,
"info": false,
columnDefs: [{
orderable: false,
className: 'select-checkbox',
targets: 0
}],
select: {
style: 'os',
selector: 'td:first-child'
},
order: [[1, 'asc']]
});
}
Answers
You need to use Datatables API's for Datatables to know about the updates and process the rows, ie, create checkboxes.
Not sure if it will work but you can try
rows().invalidate()
after appending your rows. Or you can try$('#bodyListLetter').empty()
followed byrows.add()
to use Datatablesadd()
API to add the rows.Kevin
kthorngren,
Invalidating and redrawing solved the problem.
var table = $('#example2').DataTable();
table.rows().invalidate().draw();