HTML
<div class="box">
<table id="Datatable">
<thead>
<tr>
<th><input name="checkall" type="checkbox" class="checkall" value="ON" /></th>
<th>field</th>
<th>field</th>
<th>field</th>
<th>field</th>
<th>field</th>
</tr>
</thead>
<tbody>
<tr>
<th class="checkers"><input type="checkbox" name="selected[]"/></th>
<td>value</td>
<td>value</td>
<td>value</td>
<td>value</td>
<td>value</td>
</tr>
</tbody>
</table>
</div>
I'm trying to make the checkall checkbox selects all the checkboxes using this code:
$('.checkall').click(function () {
var checkall =$(this).parents('.box:eq(0)').find(':checkbox').attr('checked', this.checked);
$.uniform.update(checkall);
});
As datatable shows the first 10,20,30 ... etc rows and removes the others from the DOM to do the pagination, this jQuery code only selects the rows in the current page. So is there anyway that I can select all checkboxes?
My solution works too:
$('.checkall').click(function(e) {
var chk = $(this).prop('checked');
$('input', oTable.fnGetNodes()).prop('checked',chk);
});
And if you want check only filtered (if you use dom for filtering in datatables), then you can use this, to check only filtered
$('.checkall').click(function(e) {
var chk = $(this).prop('checked');
$('input', oTable.$('tr', {"filter": "applied"} )).prop('checked',chk);
});
i found the solution
$('.checkall', oTable.fnGetNodes()).click(function () {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With