Skip to content

Commit 670ecf5

Browse files
committed
Fix #34. Remove support for duplicate data in a column containing checkboxes
1 parent 2f48fab commit 670ecf5

File tree

2 files changed

+21
-55
lines changed

2 files changed

+21
-55
lines changed

js/dataTables.checkboxes.js

Lines changed: 19 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
/*! Checkboxes 1.2.4
1+
/*! Checkboxes 1.2.5-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.4
9+
* @version 1.2.5-dev
1010
* @file dataTables.checkboxes.js
1111
* @author Gyrocode (http://www.gyrocode.com/projects/jquery-datatables-checkboxes/)
1212
* @contact http://www.gyrocode.com/contacts
@@ -368,14 +368,11 @@ Checkboxes.prototype = {
368368
},
369369

370370
// Updates array holding data for selected checkboxes
371-
updateData: function(type, selector, isSelected, allowDups){
371+
updateData: function(type, selector, isSelected){
372372
var self = this;
373373
var dt = self.s.dt;
374374
var ctx = self.s.ctx;
375375

376-
// By default, duplicate data is not allowed
377-
if(typeof allowDups === 'undefined'){ allowDups = false; }
378-
379376
var cellSelector;
380377

381378
if(type === 'cell'){
@@ -399,30 +396,13 @@ Checkboxes.prototype = {
399396
// Get cell data
400397
var cellData = this.data();
401398

402-
// Determine whether data is in the list
403-
var hasData = ctx.checkboxes.s.data[cellCol].hasOwnProperty(cellData);
404-
405-
// If checkbox is checked and data is not in the list
399+
// If checkbox is checked
406400
if(isSelected){
407-
// If data is available and duplicates are allowed
408-
if(hasData && allowDups){
409-
ctx.checkboxes.s.data[cellCol][cellData]++;
410-
411-
// Otherwise, if data is not available or duplicates are not allowed
412-
} else {
413-
ctx.checkboxes.s.data[cellCol][cellData] = 1;
414-
}
401+
ctx.checkboxes.s.data[cellCol][cellData] = 1;
415402

416-
// Otherwise, if checkbox is not checked and data is in the list
417-
} else if (!isSelected && hasData){
418-
// If only data counter equals to 1 or duplicates are not allowed
419-
if(ctx.checkboxes.s.data[cellCol][cellData] === 1 || !allowDups){
420-
delete ctx.checkboxes.s.data[cellCol][cellData];
421-
422-
// Otherwise, if data counter is greater than 1 and duplicates are allowed
423-
} else {
424-
ctx.checkboxes.s.data[cellCol][cellData]--;
425-
}
403+
// Otherwise, if checkbox is not checked
404+
} else {
405+
delete ctx.checkboxes.s.data[cellCol][cellData];
426406
}
427407
}
428408
});
@@ -607,21 +587,7 @@ Checkboxes.prototype = {
607587
if(self.s.ignoreSelect){ return; }
608588

609589
if(type === 'row'){
610-
// By default, allow duplicate data
611-
var allowDup = true;
612-
613-
// WORKAROUND:
614-
// Select extension may generate multiple select events for the same row
615-
// when selecting rows using SHIFT key and the following styles are used
616-
// 'os', 'multi+shift'.
617-
//
618-
// If user is selecting/deselecting multiple rows using SHIFT key
619-
if((ctx._select.style === 'os' || ctx._select.style === 'multi+shift') && indexes.length > 1){
620-
// Disallow handling of rows with duplicate data
621-
allowDup = false;
622-
}
623-
624-
self.updateData('row', indexes, (e.type === 'select') ? true : false, allowDup);
590+
self.updateData('row', indexes, (e.type === 'select') ? true : false);
625591
self.updateCheckbox('row', indexes, (e.type === 'select') ? true : false);
626592

627593
// Get index of the first column that has checkbox and row selection enabled
@@ -906,7 +872,7 @@ Api.register( 'checkboxes()', function () {
906872
return this;
907873
} );
908874

909-
Api.registerPlural( 'columns().checkboxes.select()', 'column().checkboxes.select()', function ( select, allowDups ) {
875+
Api.registerPlural( 'columns().checkboxes.select()', 'column().checkboxes.select()', function ( select ) {
910876
if(typeof select === 'undefined'){ select = true; }
911877

912878
return this.iterator( 'column-rows', function ( ctx, colIdx, i, j, rowsIdx ) {
@@ -916,7 +882,7 @@ Api.registerPlural( 'columns().checkboxes.select()', 'column().checkboxes.select
916882
selector.push({ row: rowIdx, column: colIdx });
917883
});
918884

919-
ctx.checkboxes.updateData('cell', selector, (select) ? true : false, allowDups);
885+
ctx.checkboxes.updateData('cell', selector, (select) ? true : false);
920886
ctx.checkboxes.updateCheckbox('cell', selector, (select) ? true : false);
921887

922888
// If row selection is enabled
@@ -939,14 +905,14 @@ Api.registerPlural( 'columns().checkboxes.select()', 'column().checkboxes.select
939905
}, 1 );
940906
} );
941907

942-
Api.registerPlural( 'cells().checkboxes.select()', 'cell().checkboxes.select()', function ( select, allowDups ) {
908+
Api.registerPlural( 'cells().checkboxes.select()', 'cell().checkboxes.select()', function ( select ) {
943909
if(typeof select === 'undefined'){ select = true; }
944910

945911
return this.iterator( 'cell', function ( ctx, rowIdx, colIdx ) {
946912
if(ctx.checkboxes){
947913
var selector = [{ row: rowIdx, column: colIdx }];
948914

949-
ctx.checkboxes.updateData('cell', selector, (select) ? true : false, allowDups);
915+
ctx.checkboxes.updateData('cell', selector, (select) ? true : false);
950916
ctx.checkboxes.updateCheckbox('cell', selector, (select) ? true : false);
951917

952918
// If row selection is enabled
@@ -969,12 +935,12 @@ Api.registerPlural( 'cells().checkboxes.select()', 'cell().checkboxes.select()',
969935
}, 1 );
970936
} );
971937

972-
Api.registerPlural( 'columns().checkboxes.deselect()', 'column().checkboxes.deselect()', function ( allowDups ) {
973-
return this.checkboxes.select(false, allowDups);
938+
Api.registerPlural( 'columns().checkboxes.deselect()', 'column().checkboxes.deselect()', function () {
939+
return this.checkboxes.select(false);
974940
} );
975941

976-
Api.registerPlural( 'cells().checkboxes.deselect()', 'cell().checkboxes.deselect()', function ( allowDups ) {
977-
return this.checkboxes.select(false, allowDups);
942+
Api.registerPlural( 'cells().checkboxes.deselect()', 'cell().checkboxes.deselect()', function () {
943+
return this.checkboxes.select(false);
978944
} );
979945

980946
Api.registerPlural( 'columns().checkboxes.deselectAll()', 'column().checkboxes.deselectAll()', function () {
@@ -983,7 +949,7 @@ Api.registerPlural( 'columns().checkboxes.deselectAll()', 'column().checkboxes.d
983949
if(ctx.aoColumns[colIdx].checkboxes){
984950
ctx.checkboxes.s.data[colIdx] = {};
985951

986-
this.column(colIdx).checkboxes.select(false, false);
952+
this.column(colIdx).checkboxes.select(false);
987953
}
988954
}, 1 );
989955
} );
@@ -1013,7 +979,7 @@ Api.registerPlural( 'columns().checkboxes.selected()', 'column().checkboxes.sele
1013979
* @name Checkboxes.version
1014980
* @static
1015981
*/
1016-
Checkboxes.version = '1.2.3';
982+
Checkboxes.version = '1.2.5-dev';
1017983

1018984

1019985

0 commit comments

Comments
 (0)