Reputation: 119
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?
Upvotes: 0
Views: 1593
Reputation: 58880
Use $()
DataTables API method to retrieve data from all pages, not just first page.
For example:
var $checkboxes = $('#example').DataTable().$('input[type=checkbox]:checked');
Upvotes: 1