mardi 19 novembre 2019

How can I set checkboxes checked in DataTables?

I'm trying to use the checkbox into checked when the check field of the DataTable is equal to "Checked". The code present here prints the values ​​in the table and the respective checkboxes connected to the Id, in this case the "IdTest" set as "RowId." Can anyone help me?

var table = $('#list2').DataTable({
    'scrollX': true,
    'bSort': false,
    'rowId': "IdTestResult",
    'ajax': "/nc/get_list/<?php echo $SN; ?>",
    'columnDefs': [{
        'targets': 0,
        'checkboxes': {
            'selectRow': true
        }
    }],
    columns: [{
            data: "RowId"
        },
        {
            data: "Num"
        },
        {
            data: "Description"
        },
        {
            data: "Check"
        }
    ],
    'select': {
        'style': 'multi'
    },

    'order': [
        [1, 'asc']
    ],
    "searching": false,
    "paging": false,
    "info": false

});



// Handle form submission event
$('#frm-example').on('submit', function(e) {
    var form = this;

    var rows_selected = table.column(0).checkboxes.selected();

    // Iterate over all selected checkboxes
    $.each(rows_selected, function(index, rowId) {
        // Create a hidden element
        $(form).append(
            $('<input>')
            .attr('type', 'hidden')
            .attr('name', 'id[]')
            .val(rowId)
        );
    });

});



Aucun commentaire:

Enregistrer un commentaire