Search code examples
javascriptphpjquerycheckboxdatatable

Passing data to input form inside cell datatable when checkbox selected


I have a checkbox on a table, where when that checkbox is selected it will pass data in the "sisa" variable. When in the console log , I have managed to display the "sisa" data. But how to submit the "sisa" data in the input form in the next column ("diterima" column). This checkbox is a multiple selection, so you can select many at once.

the screenshoot: https://i.postimg.cc/qq7CpVrf/error.png

My datatable

$('#produkTabel').DataTable({
    "aaData": response.result,
    "columns": [

        {
            "data": "id", "class": "text-center",
            render: function (data, type, row, meta) {
                return meta.row + meta.settings._iDisplayStart + 1;
            }
        },
        {"data": "produk.item_code"},
        {"data": "produk.name"},
        {"data": "jumlah", "class": "text-center"},
        {"data": "sisa", "class": "text-center"},
        {"data": "id", "class": "text-center", render: function ( data,row) {
                return '<input type="number"  id="inputID" class="open-input form-control bg-white" value="0">';
            },},
        {
            "data": "id",
            "class": "text-center",
            'searchable': false,
            'orderable': false,
            render: function ( data, type ,row ) {
                if ( type === 'display' ) {
                    return '<input type="checkbox" data-sisa="'+row.sisa+'" class="editor-active">';
                }
                return data;
            },
            className: "dt-body-center"
        },
    ],
    "bDestroy": true,
});

My Jquery

$('body').on('change', 'input[type="checkbox"]', function() {
    // var tblData = table.rows('.selected').data();
    let sisa = $(this).data('sisa');
    // console.log(tblData);
    // var inputForm = $(this).'input[type="number"]';
    // $('.open-input').val(sisa);
    // this.checked ? inputForm.val(sisa) : inputForm.val(0);
    console.log(sisa);
});

Solution

  • $("#inputID").val(sisa);

    Try this in your script....sorry if am wrong