Skip to content

Commit f9c6f16

Browse files
committed
Fix #14: Save/restore checkboxes selection when state saving is enabled
1 parent 784e131 commit f9c6f16

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

js/dataTables.checkboxes.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
/*! Checkboxes 1.1.0
1+
/*! Checkboxes 1.1.1
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.1.0
9+
* @version 1.1.1
1010
* @file dataTables.checkboxes.js
1111
* @author Gyrocode (http://www.gyrocode.com/projects/jquery-datatables-checkboxes/)
1212
* @contact http://www.gyrocode.com/contacts
@@ -81,6 +81,9 @@ Checkboxes.prototype = {
8181
var hasCheckboxes = false;
8282
var hasCheckboxesSelectRow = false;
8383

84+
// Retrieve stored state
85+
var state = dt.state.loaded();
86+
8487
for(var i = 0; i < ctx.aoColumns.length; i++){
8588
if (ctx.aoColumns[i].checkboxes){
8689
//
@@ -142,6 +145,12 @@ Checkboxes.prototype = {
142145
// Initialize array holding data for selected checkboxes
143146
self.s.data[i] = [];
144147

148+
// If state is loaded and contains data for this column
149+
if(state && state.checkboxes && state.checkboxes.hasOwnProperty(i)){
150+
// Load previous state
151+
self.s.data[i] = state.checkboxes[i];
152+
}
153+
145154
// Store column index for easy column selection later
146155
self.s.columns.push(i);
147156

@@ -252,6 +261,15 @@ Checkboxes.prototype = {
252261
}
253262
}
254263
});
264+
265+
// If stave saving is enabled
266+
if(ctx.oFeatures.bStateSave){
267+
// Handle state saving event
268+
dt.on('stateSaveParams.checkboxes', function (e, settings, data){
269+
// Store data associated with this plug-in
270+
data.checkboxes = self.s.data;
271+
});
272+
}
255273
}
256274
},
257275

@@ -317,6 +335,9 @@ Checkboxes.prototype = {
317335
}
318336
});
319337
}
338+
339+
// Save state
340+
dt.state.save();
320341
},
321342

322343
// Updates row selection

0 commit comments

Comments
 (0)