1
- /*! Checkboxes 1.0.2
1
+ /*! Checkboxes 1.0.3
2
2
* Copyright (c) Gyrocode (www.gyrocode.com)
3
3
* License: MIT License
4
4
*/
5
5
6
6
/**
7
7
* @summary Checkboxes
8
8
* @description Checkboxes extension for jQuery DataTables
9
- * @version 1.0.2
9
+ * @version 1.0.3
10
10
* @file dataTables.checkboxes.js
11
11
* @author Gyrocode (http://www.gyrocode.com/projects/jquery-datatables-checkboxes/)
12
12
* @contact http://www.gyrocode.com/contacts
@@ -178,6 +178,9 @@ Checkboxes.prototype = {
178
178
self . onSelect ( e , type , indexes ) ;
179
179
} ) ;
180
180
181
+ // Disable Select extension information display
182
+ dt . select . info ( false ) ;
183
+
181
184
// Otherwise, if Select extension is not available
182
185
} else {
183
186
$table_body . on ( 'click' , 'td' , function ( ) {
@@ -191,6 +194,11 @@ Checkboxes.prototype = {
191
194
$row . toggleClass ( 'selected' ) ;
192
195
} ) ;
193
196
}
197
+
198
+ // Update the table information element with selected item summary
199
+ $table . on ( 'draw.dt select.dt deselect.dt' , function ( ) {
200
+ self . showInfoSelected ( ) ;
201
+ } ) ;
194
202
}
195
203
196
204
// Handle table draw event
@@ -539,7 +547,59 @@ Checkboxes.prototype = {
539
547
}
540
548
}
541
549
}
550
+ } ,
551
+
552
+ // Updates the information element of the DataTable showing information about the
553
+ // items selected. Based on info() method of Select extension.
554
+ showInfoSelected : function ( ) {
555
+ var self = this ;
556
+ var dt = self . s . dt ;
557
+ var ctx = dt . settings ( ) [ 0 ] ;
558
+
559
+ if ( ! ctx . aanFeatures . i ) {
560
+ return ;
561
+ }
562
+
563
+ var $output = $ ( '<span class="select-info"/>' ) ;
564
+ var add = function ( name , num ) {
565
+ $output . append ( $ ( '<span class="select-item"/>' ) . append ( dt . i18n (
566
+ 'select.' + name + 's' ,
567
+ { _ : '%d ' + name + 's selected' , 0 : '' , 1 : '1 ' + name + ' selected' } ,
568
+ num
569
+ ) ) ) ;
570
+ } ;
571
+
572
+ // Find index of the first column that has checkbox and row selection enabled
573
+ var colSelectRowIdx = - 1 ;
574
+ for ( var colIdx = 0 ; colIdx < ctx . aoColumns . length ; colIdx ++ ) {
575
+ // If Checkboxes extension is enabled
576
+ // and row selection is enabled for this column
577
+ if ( ctx . aoColumns [ colIdx ] . checkboxes && ctx . aoColumns [ colIdx ] . checkboxes . selectRow ) {
578
+ colSelectRowIdx = colIdx ;
579
+ break ;
580
+ }
581
+ }
582
+
583
+ // If there is a column that has checkbox and row selection enabled
584
+ if ( colSelectRowIdx !== - 1 ) {
585
+ add ( 'row' , ctx . checkboxes . s . data [ colSelectRowIdx ] . length ) ;
586
+
587
+ // Internal knowledge of DataTables to loop over all information elements
588
+ $ . each ( ctx . aanFeatures . i , function ( i , el ) {
589
+ var $el = $ ( el ) ;
590
+
591
+ var $exisiting = $el . children ( 'span.select-info' ) ;
592
+ if ( $exisiting . length ) {
593
+ $exisiting . remove ( ) ;
594
+ }
595
+
596
+ if ( $output . text ( ) !== '' ) {
597
+ $el . append ( $output ) ;
598
+ }
599
+ } ) ;
600
+ }
542
601
}
602
+
543
603
} ;
544
604
545
605
0 commit comments