Row remove and selection does not work after cleaning the table

Row remove and selection does not work after cleaning the table

alderhernandezalderhernandez Posts: 33Questions: 11Answers: 1
edited October 2017 in Free community support

hi i have a row single selection in my document ready

$(document).ready(function () {
    var tb = $('#tblCB').DataTable();
    $('#deleteCB').click( function () {//mi button to delete row
        tb.row('.selected').remove().draw( false );
    });  

    $('#tblCB tbody').on('click', 'tr', function () {
        if ($(this).hasClass('selected')) {
            $(this).removeClass('selected');
        }
        else {
            tb.$('tr.selected').removeClass('selected');
            $(this).addClass('selected');
        }
    });
});

and i have a function to clear the data in the table

function limpiarTabla(idTabla) {
    idTabla = $(idTabla).DataTable();
    idTabla.destroy();
    idTabla.clear();
    idTabla.draw();

    //var table = $(idTabla).DataTable();
    //table.destroy().clear().draw();
    //$(idTabla).DataTable().clear().draw();
    //var table = $(idTabla).DataTable();

    //table.clear().draw();// this funtions does not work for me
    //$(idTabla).dataTable().fnClearTable();// this funtions does not work for me
}

i call the limpiarTabla() funtion before a ajax call
like this

        limpiarTabla("#tblCB")//---funtion to clear

        $('#tblCB').DataTable({
            "ajax": {
                "async": false,
                "url": "LoadCB",
                "type": "POST",
                "datatype": "json",
                destroy: true,
                "data": {
                    COD: narticulo
                }
            },
            "columns": [
                { "data": "DESC" }
            ]
        });

everything work fine but.. when i select a row the table allow me multiple rows select.

and the button '#deleteCB' delete all rows in the table (selected and not selected).

what im doing wrong?

This discussion has been closed.