Skip to content

Commit 1c48b04

Browse files
committed
Fix #44: Added ability to get data for selected checkboxes with filtering applied.
1 parent 5e4d350 commit 1c48b04

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

js/dataTables.checkboxes.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
/*! Checkboxes 1.2.9
1+
/*! Checkboxes 1.2.10-dev
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.9
9+
* @version 1.2.10-dev
1010
* @file dataTables.checkboxes.js
1111
* @author Gyrocode (http://www.gyrocode.com/projects/jquery-datatables-checkboxes/)
1212
* @contact http://www.gyrocode.com/contacts
@@ -1067,18 +1067,34 @@ Api.registerPlural( 'columns().checkboxes.deselectAll()', 'column().checkboxes.d
10671067
} );
10681068

10691069
Api.registerPlural( 'columns().checkboxes.selected()', 'column().checkboxes.selected()', function () {
1070-
return this.iterator( 'column', function (ctx, colIdx){
1070+
return this.iterator( 'column-rows', function ( ctx, colIdx, i, j, rowsIdx ) {
1071+
// If Checkboxes extension is enabled for this column
10711072
if(ctx.aoColumns[colIdx].checkboxes){
1073+
// Prepare a list of all cells
1074+
var selector = [];
1075+
$.each(rowsIdx, function(index, rowIdx){
1076+
selector.push({ row: rowIdx, column: colIdx });
1077+
});
1078+
1079+
// Get all cells data
1080+
var cells = this.cells(selector);
1081+
var cellsData = cells.data();
1082+
10721083
var data = [];
10731084

1074-
$.each(ctx.checkboxes.s.data[colIdx], function(cellData, countRows){
1075-
// If checkbox in the cell can be checked
1076-
if(ctx.checkboxes.isCellSelectable(colIdx, cellData)){
1077-
data.push(cellData);
1085+
// Enumerate all cells data
1086+
$.each(cellsData, function(index, cellData){
1087+
// If checkbox is checked
1088+
if(ctx.checkboxes.s.data[colIdx].hasOwnProperty(cellData)){
1089+
// If checkbox in the cell can be selected
1090+
if(ctx.checkboxes.isCellSelectable(colIdx, cellData)){
1091+
data.push(cellData);
1092+
}
10781093
}
10791094
});
10801095

10811096
return data;
1097+
10821098
} else {
10831099
return [];
10841100
}
@@ -1092,7 +1108,7 @@ Api.registerPlural( 'columns().checkboxes.selected()', 'column().checkboxes.sele
10921108
* @name Checkboxes.version
10931109
* @static
10941110
*/
1095-
Checkboxes.version = '1.2.9';
1111+
Checkboxes.version = '1.2.10-dev';
10961112

10971113

10981114

0 commit comments

Comments
 (0)