Skip to content

Commit b93db66

Browse files
committed
Fixed compatibility issue with FixedColumns extension when there is more than one fixed columns with checkboxes.
1 parent 380058d commit b93db66

File tree

3 files changed

+35
-25
lines changed

3 files changed

+35
-25
lines changed

js/dataTables.checkboxes.js

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,12 @@
322322

323323
// Handle table initialization event
324324
$table.on('init.dt.dtCheckboxes', function(){
325-
self.onDataTablesInit();
325+
// Use delay to handle initialization event
326+
// because certain extensions (FixedColumns) are initialized
327+
// only when initialization event is triggered.
328+
setTimeout(function(){
329+
self.onDataTablesInit();
330+
}, 0);
326331
});
327332

328333
// Handle state saving event
@@ -462,7 +467,7 @@
462467

463468
$.each(self.s.columns, function(index, colIdx){
464469
self.updateSelectAll(colIdx);
465-
});
470+
});
466471
},
467472

468473
// Handles DataTables Ajax request completion event
@@ -565,12 +570,22 @@
565570
// Update table state
566571
updateState: function(){
567572
var self = this;
573+
var dt = self.s.dt;
574+
var ctx = self.s.ctx;
568575

569576
self.updateStateCheckboxes({ page: 'all', search: 'none' });
570577

571-
$.each(self.s.columns, function(index, colIdx){
572-
self.updateSelectAll(colIdx);
573-
});
578+
// If FixedColumns extension is enabled
579+
if(ctx._oFixedColumns){
580+
// Use delay to let FixedColumns construct the header
581+
// before we update the "Select all" checkbox
582+
setTimeout(function(){
583+
// For every column where checkboxes are enabled
584+
$.each(self.s.columns, function(index, colIdx){
585+
self.updateSelectAll(colIdx);
586+
});
587+
}, 0);
588+
}
574589
},
575590

576591
// Updates state of multiple checkboxes
@@ -919,8 +934,19 @@
919934
if(ctx._oFixedColumns){
920935
var leftCols = ctx._oFixedColumns.s.iLeftColumns;
921936
var rightCols = ctx.aoColumns.length - ctx._oFixedColumns.s.iRightColumns - 1;
937+
922938
if (colIdx < leftCols || colIdx > rightCols){
939+
// Update the data shown in the fixed column
923940
dt.fixedColumns().update();
941+
942+
// Use delay to let FixedColumns construct the header
943+
// before we update the "Select all" checkbox
944+
setTimeout(function(){
945+
// For every column where checkboxes are enabled
946+
$.each(self.s.columns, function(index, colIdx){
947+
self.updateSelectAll(colIdx);
948+
});
949+
}, 0);
924950
}
925951
}
926952
}
@@ -1039,15 +1065,7 @@
10391065
ctx.checkboxes.updateSelect(rowsSelectableIdx, state);
10401066
}
10411067

1042-
// If FixedColumns extension is enabled
1043-
if(ctx._oFixedColumns){
1044-
// Use timeout to let FixedColumns construct the header
1045-
// before we update the "Select all" checkbox
1046-
setTimeout(function(){ ctx.checkboxes.updateSelectAll(colIdx); }, 0);
1047-
1048-
} else {
1049-
ctx.checkboxes.updateSelectAll(colIdx);
1050-
}
1068+
ctx.checkboxes.updateSelectAll(colIdx);
10511069

10521070
ctx.checkboxes.updateFixedColumn(colIdx);
10531071
}
@@ -1073,15 +1091,7 @@
10731091
ctx.checkboxes.updateSelect(rowIdx, state);
10741092
}
10751093

1076-
// If FixedColumns extension is enabled
1077-
if(ctx._oFixedColumns){
1078-
// Use timeout to let FixedColumns construct the header
1079-
// before we update the "Select all" checkbox
1080-
setTimeout(function(){ ctx.checkboxes.updateSelectAll(colIdx); }, 0);
1081-
1082-
} else {
1083-
ctx.checkboxes.updateSelectAll(colIdx);
1084-
}
1094+
ctx.checkboxes.updateSelectAll(colIdx);
10851095

10861096
ctx.checkboxes.updateFixedColumn(colIdx);
10871097
}

0 commit comments

Comments
 (0)