Implementing CHECKBOX in Datatables

Asked

Viewed 104 times

-2

I want to put a CHECKBOX field in the first column where I will be able to select all the records, or just a record.

var montarDataTable = function(){
if (!$.fn.DataTable.isDataTable('#reciclagem-lista')) {
    $("#reciclagem-lista").DataTable({
        oLanguage: { sUrl: "dataTable.portugues.txt"},
        dom: 'Bfrtip',
        buttons: [ 

        ],
        responsive: true,
        data: window.ds,
        pageLength: 10,
        searching: false,
        lengthChange: false,
        columns: [
            { title: "CHECKBOX"},
            { title: "Código",  data: "codigo"},
            { title: "Status",  data: "status"},
            { title: "Data do Cadastro",  data: "data_cadastro"},
        ],
        order: [[ 0, 'asc' ]]
    });
}else{
    reloadDataTable('reciclagem-lista', window.ds);
}
};

/* Recarregando dados no DataTable já criado */
function reloadDataTable(table_id, dados){
    table = $("#"+table_id).dataTable();
    oSettings = table.fnSettings();

    table.fnClearTable(this);

    if(dados.length !== 0){
        for (var i=0; i<dados.length; i++){
            table.oApi._fnAddData(oSettings, dados[i]);
        }
    }

    oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
    table.fnDraw();
}

1 answer

1


From what I understood your doubt this implementation, besides having a good explanation in the documentation LINK However there is a good article very simple and direct showing more clearly how to do, you can take a look here

Browser other questions tagged

You are not signed in. Login or sign up in order to post.