0

I have a jquery datatable when the user selects the checkbox I want it to transfer the data to the new table

However when I click to row the the data is transferred to the other table I want the row data to be transferred only when the checkbox is checked. Thank you for your help.

    $("#tblProveedorToTransfert").on('click', 'tr', function (e) {
        var $row = primaryTable.row(this).data(); //Gets row of main table
        secondTable.row.add($row).draw();   //Add row to another table          
    });

Add here is my table

var primaryTable = $('#tblProveedorToTransfert').DataTable({
            rowId: 'compras_id',
            "ajax": {
                "url": "/compra/loadCompraTableForProveedor",
                "traditional": true,
                "type": "GET",
                "datatype": "json",
                "data": function (data) {
                    data.idProveedor = @id;
                }
            },
            "columns": [
                {
                    "width": "40px", "render": function (data, type, row) { /* index = 0 */
                        return '';
                    }
                },
                {
                    "width": "10px", "render": function (data, type, row) { /* index = 0 */
                        return '<input value="0" type="checkbox" class="checkbox"  name="comprasIds" id="comprasIds" data-id="' + row.compras_id + '"  />';
                    }
                },
                { "data": "nombre_proveedor", "autoWidth": true }, /* index = 0 */
                { "data": "numero_contrato", "autoWidth": true }, /* index = 1 */
                { "data": "numero_pedido", "autoWidth": true }, /* index = 2 */
                { "data": "marca", "autoWidth": true }, /* index = 3 */
            ],
        });
    });

How can i change my code so that the data is only transferred when the check button is clicked.

J.C
  • 632
  • 1
  • 10
  • 41
  • 1
    Does this answer your question? [jQuery checkbox checked state changed event](https://stackoverflow.com/questions/8423217/jquery-checkbox-checked-state-changed-event) – andrewJames Jul 02 '20 at 20:18
  • No it does not answer my question since I want to have the row were the checkbox is clicked but thank you for you help @andrewjames – J.C Jul 02 '20 at 20:22
  • I take your point - that is more appropriate if (for example) you want to sweep all the checked rows as a batch - not as they are checked, as you need. – andrewJames Jul 02 '20 at 20:56

0 Answers0