Checkboxes not visible in DataTable second time.

Checkboxes not visible in DataTable second time.

SandyngpSandyngp Posts: 2Questions: 1Answers: 0

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

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    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 by rows.add() to use Datatables add() API to add the rows.

    Kevin

  • SandyngpSandyngp Posts: 2Questions: 1Answers: 0

    kthorngren,

    Invalidating and redrawing solved the problem.

    var table = $('#example2').DataTable();
    table.rows().invalidate().draw();

This discussion has been closed.