@@ -423,22 +423,33 @@ Checkboxes.prototype = {
423
423
var dt = self . s . dt ;
424
424
var ctx = self . s . ctx ;
425
425
426
- var nodes = [ ] ;
426
+ var cellSelector = [ ] ;
427
427
if ( type === 'row' ) {
428
428
dt . rows ( selector ) . every ( function ( rowIdx ) {
429
429
// Get index of the first column that has checkbox and row selection enabled
430
430
var colIdx = self . getSelectRowColIndex ( ) ;
431
431
if ( colIdx !== null ) {
432
- nodes . push ( dt . cell ( rowIdx , colIdx ) . node ( ) ) ;
432
+ cellSelector . push ( { row : rowIdx , column : colIdx } ) ;
433
433
}
434
434
} ) ;
435
435
436
436
} else if ( type === 'cell' ) {
437
- nodes = dt . cells ( selector ) . nodes ( ) ;
437
+ cellSelector = selector ;
438
+
438
439
}
439
440
441
+ var nodes = dt . cells ( cellSelector ) . nodes ( ) ;
440
442
if ( nodes . length ) {
441
443
$ ( 'input.dt-checkboxes' , nodes ) . prop ( 'checked' , isSelected ) ;
444
+
445
+ // NOTE: For performance reasons assume that cellSelector is always
446
+ // an array of objects with two properties: "row" and "column".
447
+ var colIdx = cellSelector [ 0 ] . column ;
448
+
449
+ // If selectCallback is a function
450
+ if ( $ . isFunction ( ctx . aoColumns [ colIdx ] . checkboxes . selectCallback ) ) {
451
+ ctx . aoColumns [ colIdx ] . checkboxes . selectCallback ( nodes , isSelected ) ;
452
+ }
442
453
}
443
454
} ,
444
455
@@ -465,7 +476,7 @@ Checkboxes.prototype = {
465
476
466
477
// If cell needs to be selected
467
478
if ( dataSeen [ cellData ] <= ctx . checkboxes . s . data [ cellCol ] [ cellData ] ) {
468
- self . updateCheckbox ( 'cell' , { row : cellRow , column : cellCol } , true ) ;
479
+ self . updateCheckbox ( 'cell' , [ { row : cellRow , column : cellCol } ] , true ) ;
469
480
470
481
// If row selection is enabled
471
482
if ( ctx . aoColumns [ cellCol ] . checkboxes . selectRow ) {
@@ -599,26 +610,33 @@ Checkboxes.prototype = {
599
610
}
600
611
}
601
612
613
+ var isSelected ;
614
+ var isIndeterminate ;
615
+
602
616
// If none of the checkboxes are checked
603
617
if ( $checkboxesChecked . length === 0 ) {
604
- $checkboxesSelectAll . prop ( {
605
- 'checked' : false ,
606
- 'indeterminate' : false
607
- } ) ;
618
+ isSelected = false ;
619
+ isIndeterminate = false ;
608
620
609
621
// If all of the checkboxes are checked
610
622
} else if ( $checkboxesChecked . length === $checkboxes . length ) {
611
- $checkboxesSelectAll . prop ( {
612
- 'checked' : true ,
613
- 'indeterminate' : false
614
- } ) ;
623
+ isSelected = true ;
624
+ isIndeterminate = false ;
615
625
616
626
// If some of the checkboxes are checked
617
627
} else {
618
- $checkboxesSelectAll . prop ( {
619
- 'checked' : true ,
620
- 'indeterminate' : true
621
- } ) ;
628
+ isSelected = true ;
629
+ isIndeterminate = true ;
630
+ }
631
+
632
+ $checkboxesSelectAll . prop ( {
633
+ 'checked' : isSelected ,
634
+ 'indeterminate' : isIndeterminate
635
+ } ) ;
636
+
637
+ // If selectAllCallback is a function
638
+ if ( $ . isFunction ( ctx . aoColumns [ colIdx ] . checkboxes . selectAllCallback ) ) {
639
+ ctx . aoColumns [ colIdx ] . checkboxes . selectAllCallback ( $checkboxesSelectAll . closest ( 'th' ) . get ( 0 ) , isSelected , isIndeterminate ) ;
622
640
}
623
641
}
624
642
} ,
@@ -740,25 +758,41 @@ Checkboxes.defaults = {
740
758
* Enable / disable row selection
741
759
*
742
760
* @type {Boolean }
743
- * @default `false`
761
+ * @default `false`
744
762
*/
745
763
selectRow : false ,
746
764
747
765
/**
748
766
* Enable / disable "select all" control in the header
749
767
*
750
768
* @type {Boolean }
751
- * @default `true`
769
+ * @default `true`
752
770
*/
753
771
selectAll : true ,
754
772
755
773
/**
756
774
* Enable / disable ability to select checkboxes from all pages
757
775
*
758
776
* @type {Boolean }
759
- * @default `true`
777
+ * @default `true`
778
+ */
779
+ selectAllPages : true ,
780
+
781
+ /**
782
+ * Checkbox select/deselect callback
783
+ *
784
+ * @type {Function }
785
+ * @default `null`
786
+ */
787
+ selectCallback : null ,
788
+
789
+ /**
790
+ * "Select all" control select/deselect callback
791
+ *
792
+ * @type {Function }
793
+ * @default `null`
760
794
*/
761
- selectAllPages : true
795
+ selectAllCallback : null
762
796
} ;
763
797
764
798
@@ -810,7 +844,7 @@ Api.registerPlural( 'cells().checkboxes.select()', 'cell().checkboxes.select()',
810
844
811
845
return this . iterator ( 'cell' , function ( ctx , rowIdx , colIdx ) {
812
846
if ( ctx . checkboxes ) {
813
- var selector = { row : rowIdx , column : colIdx } ;
847
+ var selector = [ { row : rowIdx , column : colIdx } ] ;
814
848
815
849
ctx . checkboxes . updateCheckbox ( 'cell' , selector , ( select ) ? true : false ) ;
816
850
ctx . checkboxes . updateData ( 'cell' , selector , ( select ) ? true : false , allowDups ) ;
0 commit comments