Skip to content

Commit 3103570

Browse files
committed
Corrected issue when state of checkboxes was preserved after ajax.reload() was called in client-side processing mode and state saving wasn't enabled.
1 parent e894e63 commit 3103570

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

js/dataTables.checkboxes.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
/*! Checkboxes 1.2.5
1+
/*! Checkboxes 1.2.6
22
* Copyright (c) Gyrocode (www.gyrocode.com)
33
* License: MIT License
44
*/
55

66
/**
77
* @summary Checkboxes
88
* @description Checkboxes extension for jQuery DataTables
9-
* @version 1.2.5
9+
* @version 1.2.6
1010
* @file dataTables.checkboxes.js
1111
* @author Gyrocode (http://www.gyrocode.com/projects/jquery-datatables-checkboxes/)
1212
* @contact http://www.gyrocode.com/contacts
@@ -309,27 +309,32 @@ Checkboxes.prototype = {
309309

310310
// Handle table initialization event
311311
$table.on('init.dt.dtCheckboxes', function(){
312+
// If server-side processing mode is not enabled
313+
// NOTE: Needed to avoid duplicate call to updateCheckboxes() in onDraw()
314+
if(!ctx.oFeatures.bServerSide){
312315

313-
// If state saving is enabled
314-
if(ctx.oFeatures.bStateSave){
315-
316-
// If server-side processing mode is not enabled
317-
// NOTE: Needed to avoid duplicate call to updateCheckboxes() in onDraw()
318-
if(!ctx.oFeatures.bServerSide){
319-
316+
// If state saving is enabled
317+
if(ctx.oFeatures.bStateSave){
320318
self.updateState();
319+
}
320+
321+
// Handle Ajax request completion event
322+
// NOTE: Needed to update table state
323+
// if table is reloaded via ajax.reload() API method
324+
$table.on('xhr.dt', function ( e, settings, json, xhr ) {
325+
// For every column where checkboxes are enabled
326+
$.each(self.s.columns, function(index, colIdx){
327+
// Clear data
328+
self.s.data[colIdx] = {};
329+
});
321330

322-
// Handle Ajax request completion event
323-
// NOTE: Needed to update table state
324-
// if table is reloaded via ajax.reload() API method
325-
$table.on('xhr.dt', function ( e, settings, json, xhr ) {
331+
// If state saving is enabled
332+
if(ctx.oFeatures.bStateSave){
326333
// Retrieve stored state
327334
var state = dt.state.loaded();
328335

336+
// For every column where checkboxes are enabled
329337
$.each(self.s.columns, function(index, colIdx){
330-
// Clear data
331-
self.s.data[colIdx] = {};
332-
333338
// If state is loaded and contains data for this column
334339
if(state && state.checkboxes && state.checkboxes.hasOwnProperty(colIdx)){
335340
// Load previous state
@@ -341,9 +346,12 @@ Checkboxes.prototype = {
341346
$table.one('draw.dt.dtCheckboxes', function(e){
342347
self.updateState();
343348
});
344-
});
345-
}
349+
}
350+
});
351+
}
346352

353+
// If state saving is enabled
354+
if(ctx.oFeatures.bStateSave){
347355
// Handle state saving event
348356
$table.on('stateSaveParams.dt.dtCheckboxes', function (e, settings, data){
349357
// Store data associated with this plug-in
@@ -975,7 +983,7 @@ Api.registerPlural( 'columns().checkboxes.selected()', 'column().checkboxes.sele
975983
* @name Checkboxes.version
976984
* @static
977985
*/
978-
Checkboxes.version = '1.2.5';
986+
Checkboxes.version = '1.2.6';
979987

980988

981989

0 commit comments

Comments
 (0)