Reputation: 2198
I use the DataTables jQuery plugin. In that DataTable I have created a check box in the header and every column has a check box too.
That DataTable has a few pages. What I need is when I check the header checkbox then all checkboxes should be checked in all the pages of the DataTable.
I have to access the rows of all pages at a same time.
I tried this
if($('#selectAll').is(':checked')){
$(nRow).find(':input[name=group_select_components]').iCheck('check');
}
I can check the checkboxes when I will click the paginate. But I want to access a row of the dataTable at the same time..
Upvotes: 0
Views: 315
Reputation: 665
You can do it by assigning the same class for all check boxes. So when you click to select all, all boxes will be checked.
Try this code:
$(document).ready(function() {
$('#selecctall').click(function(event) { //click event
if(this.checked) { // Check if the box is checked
$('.checkbox').each(function() { //loop through each checkbox
this.checked = true; //select all checkboxes with class "checkbox"
});
}else{
$('.checkbox').each(function() { //loop through each checkbox
this.checked = false; //deselect all checkboxes with class "checkbox"
});
}
});
});
Upvotes: 0
Reputation: 14604
You can do this if your table has an id or class.
if($('#selectAll').is(':checked'))
$("#YourTableId tr td:first-child").each(function(){$(this).find(':input[name=group_select_components]').iCheck('check')});
Here it will find checkboxes in first td
if your checkboxes are in another td
you can give index
of that td by using .eq()
. This will only loop on specific tds
.
Or If you don't want to set index of td than you can simply loop through rows
if($('#selectAll').is(':checked'))
$("YourTableId tr").each(function(){$(this).find(':input[name=group_select_components]').iCheck('check')})
Upvotes: 0
Reputation: 29683
Try the below code!!
if($('#selectAll').is(':checked')){
var table = $('#yourTableId').DataTable();
var cells = table
.cells( ":checkbox" )
.nodes();
$(cells).iCheck('check');
}
or this
if($('#selectAll').is(':checked')){
var table = $('#yourTableId').DataTable();
$(':checkbox', table.rows().nodes()).iCheck('check');
}
Upvotes: 1