@@ -159,23 +159,26 @@ Checkboxes.prototype = {
159
159
if ( ctx . aoColumns [ i ] . checkboxes . selectAll ) {
160
160
$ ( dt . column ( i ) . header ( ) )
161
161
. html ( '<input type="checkbox">' )
162
- . addClass ( 'dt-checkboxes-select-all' ) ;
162
+ . addClass ( 'dt-checkboxes-select-all' )
163
+ . attr ( 'data-col' , i ) ;
163
164
}
164
165
}
165
166
}
166
167
167
168
168
169
// If table has at least one checkbox
169
170
if ( hasCheckboxes ) {
171
+
170
172
//
171
173
// EVENT HANDLERS
172
174
//
175
+
173
176
var $table = $ ( dt . table ( ) . node ( ) ) ;
174
- var $table_body = $ ( dt . table ( ) . body ( ) ) ;
175
- var $table_header = $ ( dt . table ( ) . header ( ) ) ;
177
+ var $tableBody = $ ( dt . table ( ) . body ( ) ) ;
178
+ var $tableContainer = $ ( dt . table ( ) . container ( ) ) ;
176
179
177
180
// Handles checkbox click event
178
- $table_body . on ( 'click' , 'input.dt-checkboxes' , function ( e ) {
181
+ $tableBody . on ( 'click' , 'input.dt-checkboxes' , function ( e ) {
179
182
self . onClick ( e , this ) ;
180
183
} ) ;
181
184
@@ -193,7 +196,7 @@ Checkboxes.prototype = {
193
196
194
197
// Otherwise, if Select extension is not available
195
198
} else {
196
- $table_body . on ( 'click' , 'td' , function ( ) {
199
+ $tableContainer . on ( 'click' , 'tbody td' , function ( ) {
197
200
var $row = $ ( this ) . closest ( 'tr' ) ;
198
201
var e = {
199
202
type : ( $row . hasClass ( 'selected' ) ? 'deselect' : 'select' )
@@ -219,12 +222,12 @@ Checkboxes.prototype = {
219
222
} ) ;
220
223
221
224
// Handle click on "Select all" control
222
- $table_header . on ( 'click' , 'th.dt-checkboxes-select-all input[type="checkbox"]' , function ( e ) {
225
+ $tableContainer . on ( 'click' , 'thead th.dt-checkboxes-select-all input[type="checkbox"]' , function ( e ) {
223
226
self . onClickSelectAll ( e , this ) ;
224
227
} ) ;
225
228
226
229
// Handle click on heading containing "Select all" control
227
- $table_header . on ( 'click' , 'th.dt-checkboxes-select-all' , function ( e ) {
230
+ $tableContainer . on ( 'click' , 'thead th.dt-checkboxes-select-all' , function ( e ) {
228
231
$ ( 'input[type="checkbox"]' , this ) . trigger ( 'click' ) ;
229
232
} ) ;
230
233
}
@@ -251,9 +254,10 @@ Checkboxes.prototype = {
251
254
} else if ( type === 'cell' ) {
252
255
nodes = dt . cells ( selector ) . nodes ( ) ;
253
256
254
- dt . cells ( nodes ) . every ( function ( ) {
255
- var colIdx = this . index ( ) . column ;
256
- var rowIdx = this . index ( ) . row ;
257
+ $ . each ( nodes , function ( ) {
258
+ var cellIdx = self . getCellIndex ( this ) ;
259
+ var colIdx = cellIdx . column ;
260
+ var rowIdx = cellIdx . row ;
257
261
258
262
// If Checkboxes extension is enabled
259
263
// and row selection is enabled for this column
@@ -304,14 +308,17 @@ Checkboxes.prototype = {
304
308
nodes = dt . rows ( selector ) . nodes ( ) ;
305
309
306
310
} else if ( type === 'cell' ) {
307
- dt . cells ( selector ) . every ( function ( ) {
308
- var colIdx = this . index ( ) . column ;
309
- var rowIdx = this . index ( ) . row ;
311
+ var cellNodes = dt . cells ( selector ) . nodes ( ) ;
312
+
313
+ $ . each ( cellNodes , function ( ) {
314
+ var cellIdx = self . getCellIndex ( this ) ;
315
+ var colIdx = cellIdx . column ;
316
+ var rowIdx = cellIdx . row ;
310
317
311
318
// If Checkboxes extension is enabled
312
319
// and row selection is enabled for this column
313
320
if ( ctx . aoColumns [ colIdx ] . checkboxes && ctx . aoColumns [ colIdx ] . checkboxes . selectRow ) {
314
- nodes . push ( dt . $ ( this . node ( ) ) . closest ( 'tr' ) . get ( 0 ) ) ;
321
+ nodes . push ( dt . $ ( this ) . closest ( 'tr' ) . get ( 0 ) ) ;
315
322
}
316
323
} ) ;
317
324
}
@@ -361,26 +368,32 @@ Checkboxes.prototype = {
361
368
} else if ( type === 'cell' ) {
362
369
nodes = dt . cells ( selector ) . nodes ( ) ;
363
370
364
- dt . cells ( nodes ) . every ( function ( ) {
365
- var colIdx = this . index ( ) . column ;
366
- var rowIdx = this . index ( ) . row ;
371
+ $ . each ( nodes , function ( ) {
372
+ var cellIdx = self . getCellIndex ( this ) ;
373
+ var colIdx = cellIdx . column ;
374
+ var rowIdx = cellIdx . row ;
367
375
368
376
// If Checkboxes extension is enabled
369
377
// and row selection is enabled for this column
370
378
if ( ctx . aoColumns [ colIdx ] . checkboxes && ctx . aoColumns [ colIdx ] . checkboxes . selectRow ) {
371
379
// Get list of columns other than this cell's column
372
380
// where Checkboxes extension is enabled
373
- var columns = $ . grep ( self . s . columns , function ( value ) { return value != colIdx ; } ) ;
381
+ // and row selection is enabled
382
+ var columns = $ . grep ( self . s . columns , function ( value ) {
383
+ return ( value != colIdx ) && ctx . aoColumns [ value ] . checkboxes . selectRow ;
384
+ } ) ;
374
385
375
- // Add cells from other columns
376
- $ . merge ( nodes , dt . cells ( rowIdx , columns ) . nodes ( ) ) ;
386
+ // If there are other columns
387
+ if ( columns . length ) {
388
+ // Add cells from other columns
389
+ $ . merge ( nodes , dt . cells ( rowIdx , columns ) . nodes ( ) ) ;
390
+ }
377
391
}
378
392
} ) ;
379
393
}
380
394
381
-
382
395
if ( nodes . length ) {
383
- dt . $ ( nodes ) . find ( 'input[type="checkbox"] ' ) . prop ( 'checked' , isSelected ) ;
396
+ dt . $ ( nodes ) . find ( 'input.dt-checkboxes ' ) . prop ( 'checked' , isSelected ) ;
384
397
}
385
398
} ,
386
399
@@ -393,21 +406,17 @@ Checkboxes.prototype = {
393
406
394
407
// Get cell
395
408
var $cell = $ ( ctrl ) . closest ( 'td' ) ;
396
- var cell = dt . cell ( $cell ) ;
397
409
398
- // REPLACE: dt.cells($cell).checkbox.select()
410
+ // TODO: Possibly replace with dt.cells($cell).checkbox.select()
399
411
400
412
// Get cell's column index
401
- var cellCol = cell . index ( ) . column ;
402
-
403
- // Get cell data
404
- var cellData = cell . data ( ) ;
413
+ var cellIdx = self . getCellIndex ( $cell ) ;
405
414
406
415
// If Checkboxes extension is enabled for this column
407
- if ( ctx . aoColumns [ cellCol ] . checkboxes ) {
408
- self . updateCheckbox ( 'cell' , $cell , ctrl . checked ) ;
409
- self . updateData ( 'cell' , $cell , ctrl . checked ) ;
410
- self . updateSelect ( 'cell' , $cell , ctrl . checked ) ;
416
+ if ( ctx . aoColumns [ cellIdx . column ] . checkboxes ) {
417
+ self . updateCheckbox ( 'cell' , cellIdx , ctrl . checked ) ;
418
+ self . updateData ( 'cell' , cellIdx , ctrl . checked ) ;
419
+ self . updateSelect ( 'cell' , cellIdx , ctrl . checked ) ;
411
420
self . updateSelectAll ( ) ;
412
421
413
422
// Prevent click event from propagating to parent
@@ -437,7 +446,16 @@ Checkboxes.prototype = {
437
446
var ctx = dt . settings ( ) [ 0 ] ;
438
447
439
448
// Calculate column index
440
- var col = dt . column ( $ ( ctrl ) . closest ( 'th' ) ) . index ( ) ;
449
+ var col = null ;
450
+ var $th = $ ( ctrl ) . closest ( 'th' ) ;
451
+
452
+ // If column is fixed using FixedColumns extension
453
+ if ( $th . parents ( '.DTFC_Cloned' ) . length ) {
454
+ var cellIdx = dt . fixedColumns ( ) . cellIndex ( $th ) ;
455
+ col = cellIdx . column ;
456
+ } else {
457
+ col = dt . column ( $th ) . index ( ) ;
458
+ }
441
459
442
460
var cells = dt . cells ( 'tr' , col , {
443
461
page : (
@@ -467,6 +485,12 @@ Checkboxes.prototype = {
467
485
468
486
self . updateSelectAll ( ) ;
469
487
488
+ // If column is fixed using FixedColumns extension
489
+ if ( $th . parents ( '.DTFC_Cloned' ) . length ) {
490
+ // Update columns in the cloned table
491
+ dt . fixedColumns ( ) . update ( ) ;
492
+ }
493
+
470
494
e . stopPropagation ( ) ;
471
495
} ,
472
496
@@ -525,31 +549,31 @@ Checkboxes.prototype = {
525
549
search : 'applied'
526
550
} ) ;
527
551
528
- var $table = dt . table ( ) . container ( ) ;
529
- var $chkbox_all = dt . $ ( cells . nodes ( ) ) . find ( 'input[type="checkbox"] ' ) ;
530
- var $chkbox_checked = dt . $ ( cells . nodes ( ) ) . find ( 'input[type="checkbox"] :checked' ) ;
531
- var chkbox_select_all = $ ( 'input[type="checkbox"]' , dt . column ( colIdx ) . header ( ) ) . get ( 0 ) ;
552
+ var $tableContainer = dt . table ( ) . container ( ) ;
553
+ var $checkboxes = dt . $ ( cells . nodes ( ) ) . find ( '.dt-checkboxes ' ) ;
554
+ var $checkboxesChecked = dt . $ ( cells . nodes ( ) ) . find ( '.dt-checkboxes :checked' ) ;
555
+ var $checkboxesSelectAll = $ ( '.dt-checkboxes-select-all[data-col="' + colIdx + '"] input[type="checkbox"]', $tableContainer ) ;
532
556
533
557
// If none of the checkboxes are checked
534
- if ( $chkbox_checked . length === 0 ) {
535
- chkbox_select_all . checked = false ;
536
- if ( 'indeterminate' in chkbox_select_all ) {
537
- chkbox_select_all . indeterminate = false ;
538
- }
558
+ if ( $checkboxesChecked . length === 0 ) {
559
+ $checkboxesSelectAll . prop ( {
560
+ 'checked' : false ,
561
+ ' indeterminate' : false
562
+ } ) ;
539
563
540
564
// If all of the checkboxes are checked
541
- } else if ( $chkbox_checked . length === $chkbox_all . length ) {
542
- chkbox_select_all . checked = true ;
543
- if ( 'indeterminate' in chkbox_select_all ) {
544
- chkbox_select_all . indeterminate = false ;
545
- }
565
+ } else if ( $checkboxesChecked . length === $checkboxes . length ) {
566
+ $checkboxesSelectAll . prop ( {
567
+ 'checked' : true ,
568
+ ' indeterminate' : false
569
+ } ) ;
546
570
547
571
// If some of the checkboxes are checked
548
572
} else {
549
- chkbox_select_all . checked = true ;
550
- if ( 'indeterminate' in chkbox_select_all ) {
551
- chkbox_select_all . indeterminate = true ;
552
- }
573
+ $checkboxesSelectAll . prop ( {
574
+ 'checked' : true ,
575
+ ' indeterminate' : true
576
+ } ) ;
553
577
}
554
578
}
555
579
}
@@ -594,18 +618,32 @@ Checkboxes.prototype = {
594
618
$ . each ( ctx . aanFeatures . i , function ( i , el ) {
595
619
var $el = $ ( el ) ;
596
620
597
- var $exisiting = $el . children ( 'span.select-info' ) ;
598
- if ( $exisiting . length ) {
599
- $exisiting . remove ( ) ;
621
+ var $existing = $el . children ( 'span.select-info' ) ;
622
+ if ( $existing . length ) {
623
+ $existing . remove ( ) ;
600
624
}
601
625
602
626
if ( $output . text ( ) !== '' ) {
603
627
$el . append ( $output ) ;
604
628
}
605
629
} ) ;
606
630
}
607
- }
631
+ } ,
608
632
633
+ // Gets cell index
634
+ getCellIndex : function ( cell ) {
635
+ var self = this ;
636
+ var dt = self . s . dt ;
637
+ var ctx = dt . settings ( ) [ 0 ] ;
638
+
639
+ // If FixedColumns extension is available
640
+ if ( DataTable . FixedColumns ) {
641
+ return dt . fixedColumns ( ) . cellIndex ( cell ) ;
642
+
643
+ } else {
644
+ return dt . cell ( cell ) . index ( ) ;
645
+ }
646
+ }
609
647
} ;
610
648
611
649
0 commit comments