@@ -486,18 +486,24 @@ Checkboxes.prototype = {
486
486
// Get cell data
487
487
var cellData = this . data ( ) ;
488
488
489
- // If checkbox in the cell can be checked
490
- if ( self . isCellSelectable ( colIdx , cellData ) ) {
491
- // If data is in the list
492
- if ( ctx . checkboxes . s . data [ colIdx ] . hasOwnProperty ( cellData ) ) {
493
- self . updateCheckbox ( this , colIdx , true ) ;
489
+ // Determine if checkbox in the cell can be checked
490
+ var isCellSelectable = self . isCellSelectable ( colIdx , cellData ) ;
494
491
495
- // If row selection is enabled
496
- if ( ctx . aoColumns [ colIdx ] . checkboxes . selectRow ) {
497
- self . updateSelect ( rowIdx , true ) ;
498
- }
492
+ // If checkbox is selected
493
+ if ( ctx . checkboxes . s . data [ colIdx ] . hasOwnProperty ( cellData ) ) {
494
+ self . updateCheckbox ( this , colIdx , true ) ;
495
+
496
+ // If row selection is enabled
497
+ // and checkbox can be checked
498
+ if ( ctx . aoColumns [ colIdx ] . checkboxes . selectRow && isCellSelectable ) {
499
+ self . updateSelect ( rowIdx , true ) ;
499
500
}
500
501
}
502
+
503
+ // If checkbox is disabled
504
+ if ( ! isCellSelectable ) {
505
+ $ ( 'input.dt-checkboxes' , this . node ( ) ) . prop ( 'disabled' , true ) ;
506
+ }
501
507
} ) ;
502
508
} ,
503
509
@@ -618,7 +624,11 @@ Checkboxes.prototype = {
618
624
var ctx = self . s . ctx ;
619
625
620
626
// If server-side processing is enabled
621
- if ( ctx . oFeatures . bServerSide ) {
627
+ // or deferred render is enabled
628
+ //
629
+ // TODO: it's not optimal to update state of checkboxes
630
+ // for already created rows in deferred rendering mode
631
+ if ( ctx . oFeatures . bServerSide || ctx . oFeatures . bDeferRender ) {
622
632
self . updateStateCheckboxes ( { page : 'current' , search : 'none' } ) ;
623
633
}
624
634
@@ -646,10 +656,14 @@ Checkboxes.prototype = {
646
656
} ) ;
647
657
648
658
var $tableContainer = dt . table ( ) . container ( ) ;
649
- var $checkboxes = $ ( '.dt-checkboxes' , cells . nodes ( ) ) . not ( ':disabled' ) ;
650
- var $checkboxesChecked = $checkboxes . filter ( ':checked' ) . not ( ':disabled' ) ;
651
659
var $checkboxesSelectAll = $ ( '.dt-checkboxes-select-all[data-col="' + colIdx + '"] input[type="checkbox"]' , $tableContainer ) ;
652
660
661
+ var countChecked = 0 ;
662
+ var cellsData = cells . data ( ) ;
663
+ $ . each ( cellsData , function ( index , cellData ) {
664
+ if ( self . s . data [ colIdx ] . hasOwnProperty ( cellData ) ) { countChecked ++ ; }
665
+ } ) ;
666
+
653
667
// If FixedHeader is enabled in this instance
654
668
if ( ctx . _fixedHeader ) {
655
669
// If header is floating in this instance
@@ -662,12 +676,12 @@ Checkboxes.prototype = {
662
676
var isIndeterminate ;
663
677
664
678
// If none of the checkboxes are checked
665
- if ( $checkboxesChecked . length === 0 ) {
679
+ if ( countChecked === 0 ) {
666
680
isSelected = false ;
667
681
isIndeterminate = false ;
668
682
669
683
// If all of the checkboxes are checked
670
- } else if ( $checkboxesChecked . length === $checkboxes . length ) {
684
+ } else if ( countChecked === cellsData . length ) {
671
685
isSelected = true ;
672
686
isIndeterminate = false ;
673
687
@@ -973,7 +987,12 @@ Api.registerPlural( 'cells().checkboxes.enable()', 'cell().checkboxes.enable()',
973
987
delete ctx . checkboxes . s . dataDisabled [ colIdx ] [ cellData ] ;
974
988
}
975
989
976
- $ ( 'input.dt-checkboxes' , cell . node ( ) ) . prop ( 'disabled' , state ) ;
990
+ // Determine if cell node is available
991
+ // (deferRender is not enabled or cell has been already created)
992
+ var cellNode = cell . node ( ) ;
993
+ if ( cellNode ) {
994
+ $ ( 'input.dt-checkboxes' , cellNode ) . prop ( 'disabled' , state ) ;
995
+ }
977
996
978
997
// If row selection is enabled
979
998
if ( ctx . aoColumns [ colIdx ] . checkboxes . selectRow ) {
0 commit comments