I am using the Datatable plugin and i use checkboxes in the table. I want to achieve using the Header checkbox to check all the single checkboxes and check each checkboxes to count and display each and all. Also I want display (hide and show) a div while checking the checkboxes.
I have been able to achieve checking all, but i want to check each too (in respect to the header checkbox) i.e if all is checked, the header will all be checked, if one is unchecked, it unchecks the header checkbox and vice versa. This is my code
$('#selectAllCheck').change(function(e) {
var chk = $(this).prop('checked');
var currentRows = $('#example tbody tr');
$.each(currentRows, function(){
$(this).find(':checkbox[name=haschecked]').each(function(){
$(this).prop('checked', chk);
$(':checkbox[name=haschecked]').prop('checked', chk );
$('#inboxcheck')[ chk ? 'show' : 'hide' ](); // Hide and show div
$('.checkbox-logo-pane')[ chk ? 'show' : 'hide' ](); // Hide and show div
do_count();
});
});
});
var do_count =function(){
var n = $(':checkbox[name=haschecked]:checked').length;
$('.inbox-counter').html( n ); // The checkbox counter
return n
}
});
Aucun commentaire:
Enregistrer un commentaire