Get checked row after checked dynamically from Ajax

Get checked row after checked dynamically from Ajax

simsar78simsar78 Posts: 3Questions: 1Answers: 0
edited January 2021 in Free community support

Hello,
i have this table rendered whit Ajax from database:

    <table id="list" class="table table-striped table-bordered table-sm no-footer dataTable" style="width: 100%; font-size: 14px;" role="grid" aria-describedby="list">
              <thead>
                <tr role="row">
    <th class="select-checkbox sorting_asc" tabindex="0" aria-controls="list" rowspan="1" colspan="1" aria-label="" style="width: 0px;"></th>
    <th class="sorting" tabindex="0" aria-controls="list" rowspan="1" colspan="1" aria-label="Code: activate to sort column ascending" style="width: 0px;">Code</th>
    </th></tr>
              </thead>
              <tbody>
              <tr class="odd">
<td class="select-checkbox sorting_1"></td>
    <td>18081</td>
    // ...

AJAX:

    $('#list').DataTable().destroy();
      table = $('#list').DataTable( {
        "ajax": {
          "url": "requests/List.php",
          "type": "POST",
          "data": {"id":id},
          "dataType": "json",
          "cache": false,
          "dataSrc": ""
        },
        "columns" : [
          { "data": null, defaultContent: '' },
          { "data": "code" },

        ],
        columnDefs: [ {
          orderable: false,
          className: 'select-checkbox',
          targets:   0,      
        } ],
        createdRow: function (row, data, index) {

          $.each(data_dip, function (k, v) {
           // check dynamically checkbox in column 0
            if(data.codice == v.codice){

              $(row).addClass('selected');

            }
          });
          //
        },
        select: {
          style:    'multi',
          selector: 'td:first-child'
        },
        "lengthMenu": [[20, 50, 100, -1], [20, 50, 100, "Tutti"]]
      });

if request the selected rows I have no result:

var selectedCodOpe = table.rows( { selected: true } ).data().toArray()

Why ?

  • data_dip is my array

This question has an accepted answers - jump to answer

Answers

This discussion has been closed.