Skip to content

Commit 9796ea9

Browse files
committed
Fix #57: Added checkboxes.stateSave option to disable checkbox state saving if state saving is enabled globally
1 parent b1ee938 commit 9796ea9

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

js/dataTables.checkboxes.js

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,11 @@
188188

189189
// If state is loaded and contains data for this column
190190
if(state && state.checkboxes && state.checkboxes.hasOwnProperty(i)){
191-
// Load previous state
192-
self.s.data[i] = state.checkboxes[i];
191+
// If checkbox state saving is enabled
192+
if(ctx.aoColumns[i].checkboxes.stateSave){
193+
// Load previous state
194+
self.s.data[i] = state.checkboxes[i];
195+
}
193196
}
194197

195198
// Store column index for easy column selection later
@@ -373,8 +376,11 @@
373376
$.each(self.s.columns, function(index, colIdx){
374377
// If state is loaded and contains data for this column
375378
if(state && state.checkboxes && state.checkboxes.hasOwnProperty(colIdx)){
376-
// Load previous state
377-
self.s.data[colIdx] = state.checkboxes[colIdx];
379+
// If checkbox state saving is enabled
380+
if(ctx.aoColumns[colIdx].checkboxes.stateSave){
381+
// Load previous state
382+
self.s.data[colIdx] = state.checkboxes[colIdx];
383+
}
378384
}
379385
});
380386

@@ -390,8 +396,17 @@
390396
if(ctx.oFeatures.bStateSave){
391397
// Handle state saving event
392398
$table.on('stateSaveParams.dt.dtCheckboxes', function (e, settings, data){
393-
// Store data associated with this plug-in
394-
data.checkboxes = self.s.data;
399+
// Initialize array holding checkbox state for each column
400+
data.checkboxes = [];
401+
402+
// For every column where checkboxes are enabled
403+
$.each(self.s.columns, function(index, colIdx){
404+
// If checkbox state saving is enabled
405+
if(ctx.aoColumns[colIdx].checkboxes.stateSave){
406+
// Store data associated with this plug-in
407+
data.checkboxes[colIdx] = self.s.data[colIdx];
408+
}
409+
});
395410
});
396411
}
397412
});
@@ -442,8 +457,11 @@
442457

443458
// If state saving is enabled
444459
if(ctx.oFeatures.bStateSave){
445-
// Save state
446-
dt.state.save();
460+
// If checkbox state saving is enabled
461+
if(ctx.aoColumns[colIdx].checkboxes.stateSave){
462+
// Save state
463+
dt.state.save();
464+
}
447465
}
448466
}
449467
},
@@ -871,6 +889,14 @@
871889
* @static
872890
*/
873891
Checkboxes.defaults = {
892+
/**
893+
* Enable / disable checkbox state loading/saving if state saving is enabled globally
894+
*
895+
* @type {Boolean}
896+
* @default `true`
897+
*/
898+
stateSave: true,
899+
874900
/**
875901
* Enable / disable row selection
876902
*

0 commit comments

Comments
 (0)