delete row

delete row

yoppyyoppy Posts: 1Questions: 1Answers: 0
edited February 2018 in Free community support

i have : tbl_source as Datatable.
we assume the tbl_source have 3 row data.

this my event code,

$('#tbl_source tbody').on( 'click', 'tr', function () {
        var data1 = tbl_source.rows().data(); // 3 row data

        $(this).closest("tr").remove(); // i want to remove 1 row by event click

        var data2 = tbl_source.rows().data(); // but, it's still have 3 row data (Not remove)

});

so, my question is how to really remove row in datatable?

Answers

  • kthorngrenkthorngren Posts: 20,394Questions: 26Answers: 4,786
    edited February 2018

    Its probably best to use Datatables API's for this. See if this helps:

    $('#tbl_source tbody').on( 'click', 'tr', function () {
            var row = tbl_source
                       .row($(this).closest("tr"))   //get DT API for the clicked row
                       .remove()
                       .draw();
    });
    

    Kevin

  • allanallan Posts: 61,916Questions: 1Answers: 10,149 Site admin

    Yes - you need to use the API as Kevin says. See this FAQ for why.

    Allan

This discussion has been closed.