Tuesday, May 23, 2017

Check/uncheck all checkbox



var oTable = $('#tableId').dataTable();
// << Checkbox Check All
 $('#chbDeleteAllId').change(function() {
        if($(this).is(":checked")) {
            $(':checkbox', t.rows().nodes()).prop('checked', this.checked);
        }else{
         $(':checkbox', t.rows().nodes()).prop('checked', this.checked);
        }
    });
 // Checkbox Check All >>
 
 // << Unchecked CheckAll 
 $("input[name='chbDelete']").change(function() {
  var totalChbs =  $(':checkbox', t.rows().nodes()).length;
  var totalChecked = 0;
        
        var checkboxes = $(':checkbox', t.rows().nodes());
        $.each( checkboxes, function( key, value ) {
           if(this.checked){
            totalChecked++;
           }
         });
        
        if(totalChecked == totalChbs){
         $('#chbDeleteAllId').prop('checked', true);
        }else{
         $('#chbDeleteAllId').prop('checked', false);
        }
    });
 // Unchecked CheckAll >>

No comments:

Post a Comment