Skip to content

Commit c07aeb2

Browse files
committed
Fix #49: Call selectAllCallback only when state of "Select All" control changes
1 parent 252b210 commit c07aeb2

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

js/dataTables.checkboxes.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,9 @@ Checkboxes.prototype = {
627627
colIdx = dt.column($th).index();
628628
}
629629

630+
// Indicate that state of "Select all" control has been changed
631+
$(ctrl).data('is-changed', true);
632+
630633
dt.column(colIdx, {
631634
page: (
632635
(ctx.aoColumns[colIdx].checkboxes && ctx.aoColumns[colIdx].checkboxes.selectAllPages)
@@ -714,14 +717,24 @@ Checkboxes.prototype = {
714717
isIndeterminate = true;
715718
}
716719

717-
$checkboxesSelectAll.prop({
718-
'checked': isSelected,
719-
'indeterminate': isIndeterminate
720-
});
720+
var isChanged = $checkboxesSelectAll.data('is-changed');
721+
var isSelectedNow = $checkboxesSelectAll.prop('checked');
722+
var isIndeterminateNow = $checkboxesSelectAll.prop('indeterminate');
723+
724+
// If state of "Select all" control has been changed
725+
if(isChanged || isSelectedNow !== isSelected || isIndeterminateNow !== isIndeterminate){
726+
// Reset "Select all" control state flag
727+
$checkboxesSelectAll.data('is-changed', false);
721728

722-
// If selectAllCallback is a function
723-
if($.isFunction(ctx.aoColumns[colIdx].checkboxes.selectAllCallback)){
724-
ctx.aoColumns[colIdx].checkboxes.selectAllCallback($checkboxesSelectAll.closest('th').get(0), isSelected, isIndeterminate);
729+
$checkboxesSelectAll.prop({
730+
'checked': isSelected,
731+
'indeterminate': isIndeterminate
732+
});
733+
734+
// If selectAllCallback is a function
735+
if($.isFunction(ctx.aoColumns[colIdx].checkboxes.selectAllCallback)){
736+
ctx.aoColumns[colIdx].checkboxes.selectAllCallback($checkboxesSelectAll.closest('th').get(0), isSelected, isIndeterminate);
737+
}
725738
}
726739
}
727740
},

0 commit comments

Comments
 (0)