@@ -423,22 +423,33 @@ Checkboxes.prototype = {
423423 var dt = self . s . dt ;
424424 var ctx = self . s . ctx ;
425425
426- var nodes = [ ] ;
426+ var cellSelector = [ ] ;
427427 if ( type === 'row' ) {
428428 dt . rows ( selector ) . every ( function ( rowIdx ) {
429429 // Get index of the first column that has checkbox and row selection enabled
430430 var colIdx = self . getSelectRowColIndex ( ) ;
431431 if ( colIdx !== null ) {
432- nodes . push ( dt . cell ( rowIdx , colIdx ) . node ( ) ) ;
432+ cellSelector . push ( { row : rowIdx , column : colIdx } ) ;
433433 }
434434 } ) ;
435435
436436 } else if ( type === 'cell' ) {
437- nodes = dt . cells ( selector ) . nodes ( ) ;
437+ cellSelector = selector ;
438+
438439 }
439440
441+ var nodes = dt . cells ( cellSelector ) . nodes ( ) ;
440442 if ( nodes . length ) {
441443 $ ( '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+ }
442453 }
443454 } ,
444455
@@ -465,7 +476,7 @@ Checkboxes.prototype = {
465476
466477 // If cell needs to be selected
467478 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 ) ;
469480
470481 // If row selection is enabled
471482 if ( ctx . aoColumns [ cellCol ] . checkboxes . selectRow ) {
@@ -599,26 +610,33 @@ Checkboxes.prototype = {
599610 }
600611 }
601612
613+ var isSelected ;
614+ var isIndeterminate ;
615+
602616 // If none of the checkboxes are checked
603617 if ( $checkboxesChecked . length === 0 ) {
604- $checkboxesSelectAll . prop ( {
605- 'checked' : false ,
606- 'indeterminate' : false
607- } ) ;
618+ isSelected = false ;
619+ isIndeterminate = false ;
608620
609621 // If all of the checkboxes are checked
610622 } else if ( $checkboxesChecked . length === $checkboxes . length ) {
611- $checkboxesSelectAll . prop ( {
612- 'checked' : true ,
613- 'indeterminate' : false
614- } ) ;
623+ isSelected = true ;
624+ isIndeterminate = false ;
615625
616626 // If some of the checkboxes are checked
617627 } 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 ) ;
622640 }
623641 }
624642 } ,
@@ -740,25 +758,41 @@ Checkboxes.defaults = {
740758 * Enable / disable row selection
741759 *
742760 * @type {Boolean }
743- * @default `false`
761+ * @default `false`
744762 */
745763 selectRow : false ,
746764
747765 /**
748766 * Enable / disable "select all" control in the header
749767 *
750768 * @type {Boolean }
751- * @default `true`
769+ * @default `true`
752770 */
753771 selectAll : true ,
754772
755773 /**
756774 * Enable / disable ability to select checkboxes from all pages
757775 *
758776 * @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`
760794 */
761- selectAllPages : true
795+ selectAllCallback : null
762796} ;
763797
764798
@@ -810,7 +844,7 @@ Api.registerPlural( 'cells().checkboxes.select()', 'cell().checkboxes.select()',
810844
811845 return this . iterator ( 'cell' , function ( ctx , rowIdx , colIdx ) {
812846 if ( ctx . checkboxes ) {
813- var selector = { row : rowIdx , column : colIdx } ;
847+ var selector = [ { row : rowIdx , column : colIdx } ] ;
814848
815849 ctx . checkboxes . updateCheckbox ( 'cell' , selector , ( select ) ? true : false ) ;
816850 ctx . checkboxes . updateData ( 'cell' , selector , ( select ) ? true : false , allowDups ) ;
0 commit comments