0

I have the next Datatable

HTML

<table id="example" class="row-border hover">
  <thead>
    <tr>
      <th>ID</th>
      <th>Iden.</th>
      <th>Nombres</th>
      <th>Sel.</th>
    </tr>
  </thead>
  <tbody></tbody>
  <tfoot>
    <tr>
      <th>ID</th>
      <th>Iden.</th>
      <th>Nombres</th>
      <th>Sel.</th>
    </tr>
  </tfoot>
</table>

JS

$('#example').DataTable({
    scrollX: true,
    deferRender: true,
    "aaData": data.Data,
    "columns": [{ data: "ID" },
                { data: "Identificacion" },
                { data: "Nombres" },
                { "data"      : null,
                  "targets"   : -1,
                  "orderable" : false,
                  "className" : "all",
                  "width"     : "20px",
                  "render"    : function(data, type, full) {
                                  let texto = "";
                                  texto = '<input type="checkbox" id="check_test" value="' + data.ID + '" />';
                                  return texto;
                              }
                }
               ]
});

I want get value of the selected checkboxes, so i tried this

var aux = [];

aux = $('#example tbody input[type=checkbox]:checked').map(function(_, el) {
        return $(el).val();
      }).get();

however, this only obtains the values selected from the active page of the pagination datatable

How can I get the value of the selected checkboxes on all pages of datable?

1
  • Can you also share your paginated html output? Commented Oct 9, 2019 at 15:49

1 Answer 1

1

Use $() DataTables API method to retrieve data from all pages, not just first page.

For example:

var $checkboxes = $('#example').DataTable().$('input[type=checkbox]:checked');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.