1
- /*! Checkboxes 1.0.4
1
+ /*! Checkboxes 1.1.0-dev
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.4
9
+ * @version 1.1.0-dev
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
@@ -78,13 +78,17 @@ Checkboxes.prototype = {
78
78
var self = this ;
79
79
var dt = self . s . dt ;
80
80
var ctx = dt . settings ( ) [ 0 ] ;
81
+ var hasCheckboxes = false ;
82
+ var hasCheckboxesSelectRow = false ;
81
83
82
84
for ( var i = 0 ; i < ctx . aoColumns . length ; i ++ ) {
83
85
if ( ctx . aoColumns [ i ] . checkboxes ) {
84
86
//
85
87
// INITIALIZATION
86
88
//
87
89
90
+ hasCheckboxes = true ;
91
+
88
92
if ( ! $ . isPlainObject ( ctx . aoColumns [ i ] . checkboxes ) ) {
89
93
ctx . aoColumns [ i ] . checkboxes = { } ;
90
94
}
@@ -108,7 +112,7 @@ Checkboxes.prototype = {
108
112
'className' : 'dt-body-center' ,
109
113
'render' : function ( data , type , full , meta ) {
110
114
if ( type === 'display' ) {
111
- data = '<input type="checkbox">' ;
115
+ data = '<input type="checkbox" class="dt-checkboxes" >' ;
112
116
}
113
117
return data ;
114
118
}
@@ -147,77 +151,82 @@ Checkboxes.prototype = {
147
151
//
148
152
149
153
if ( ctx . aoColumns [ i ] . checkboxes . selectRow ) {
150
- $ ( dt . table ( ) . node ( ) ) . addClass ( 'checkboxes-select' ) ;
154
+ hasCheckboxesSelectRow = true ;
155
+
156
+ $ ( dt . table ( ) . node ( ) ) . addClass ( 'dt-checkboxes-select' ) ;
151
157
}
152
158
153
159
if ( ctx . aoColumns [ i ] . checkboxes . selectAll ) {
154
160
$ ( dt . column ( i ) . header ( ) )
155
161
. html ( '<input type="checkbox">' )
156
- . addClass ( 'checkboxes-select-all' ) ;
162
+ . addClass ( 'dt- checkboxes-select-all' ) ;
157
163
}
164
+ }
165
+ }
158
166
159
167
160
- //
161
- // EVENT HANDLERS
162
- //
163
- var $table = $ ( dt . table ( ) . node ( ) ) ;
164
- var $table_body = $ ( dt . table ( ) . body ( ) ) ;
165
- var $table_header = $ ( dt . table ( ) . header ( ) ) ;
168
+ // If table has at least one checkbox
169
+ if ( hasCheckboxes ) {
170
+ //
171
+ // EVENT HANDLERS
172
+ //
173
+ var $table = $ ( dt . table ( ) . node ( ) ) ;
174
+ var $table_body = $ ( dt . table ( ) . body ( ) ) ;
175
+ var $table_header = $ ( dt . table ( ) . header ( ) ) ;
166
176
167
- // Handles checkbox click event
168
- $table_body . on ( 'click' , 'input[type="checkbox"] ' , function ( e ) {
169
- self . onClick ( e , this ) ;
170
- } ) ;
177
+ // Handles checkbox click event
178
+ $table_body . on ( 'click' , 'input.dt-checkboxes ' , function ( e ) {
179
+ self . onClick ( e , this ) ;
180
+ } ) ;
171
181
172
- // Handle row select/deselect event
173
- if ( ctx . aoColumns [ i ] . checkboxes . selectRow ) {
174
- // If Select extension is available
175
- if ( DataTable . select ) {
176
- // Handle row selection event
177
- $table . on ( 'select.dt deselect.dt' , function ( e , api , type , indexes ) {
178
- self . onSelect ( e , type , indexes ) ;
179
- } ) ;
180
-
181
- // Disable Select extension information display
182
- dt . select . info ( false ) ;
183
-
184
- // Otherwise, if Select extension is not available
185
- } else {
186
- $table_body . on ( 'click' , 'td' , function ( ) {
187
- var $row = $ ( this ) . closest ( 'tr' ) ;
188
- var e = {
189
- type : ( $row . hasClass ( 'selected' ) ? 'deselect' : 'select' )
190
- } ;
191
-
192
- self . onSelect ( e , 'row' , [ dt . row ( $row ) . index ( ) ] ) ;
193
-
194
- $row . toggleClass ( 'selected' ) ;
195
-
196
- $table . trigger ( e . type ) ;
197
- } ) ;
198
- }
182
+ // Handle row select/deselect event
183
+ if ( hasCheckboxesSelectRow ) {
184
+ // If Select extension is available
185
+ if ( DataTable . select ) {
186
+ // Handle row selection event
187
+ $table . on ( 'select.dt deselect.dt' , function ( e , api , type , indexes ) {
188
+ self . onSelect ( e , type , indexes ) ;
189
+ } ) ;
190
+
191
+ // Disable Select extension information display
192
+ dt . select . info ( false ) ;
199
193
200
- // Update the table information element with selected item summary
201
- $table . on ( 'draw.dt select.dt deselect.dt' , function ( ) {
202
- self . showInfoSelected ( ) ;
194
+ // Otherwise, if Select extension is not available
195
+ } else {
196
+ $table_body . on ( 'click' , 'td' , function ( ) {
197
+ var $row = $ ( this ) . closest ( 'tr' ) ;
198
+ var e = {
199
+ type : ( $row . hasClass ( 'selected' ) ? 'deselect' : 'select' )
200
+ } ;
201
+
202
+ self . onSelect ( e , 'row' , [ dt . row ( $row ) . index ( ) ] ) ;
203
+
204
+ $row . toggleClass ( 'selected' ) ;
205
+
206
+ $table . trigger ( e . type ) ;
203
207
} ) ;
204
208
}
205
209
206
- // Handle table draw event
207
- $table . on ( 'draw.dt' , function ( e , ctx ) {
208
- self . onDraw ( e , ctx ) ;
210
+ // Update the table information element with selected item summary
211
+ $table . on ( 'draw.dt select.dt deselect.dt ' , function ( ) {
212
+ self . showInfoSelected ( ) ;
209
213
} ) ;
214
+ }
210
215
211
- // Handle click on "Select all" control
212
- $table_header . on ( 'click' , 'th.checkboxes-select-all input[type="checkbox"] ', function ( e ) {
213
- self . onClickSelectAll ( e , this ) ;
214
- } ) ;
216
+ // Handle table draw event
217
+ $table . on ( 'draw.dt ' , function ( e , ctx ) {
218
+ self . onDraw ( e , ctx ) ;
219
+ } ) ;
215
220
216
- // Handle click on heading containing "Select all" control
217
- $table_header . on ( 'click' , 'th.checkboxes-select-all' , function ( e ) {
218
- $ ( 'input[type="checkbox"]' , this ) . trigger ( 'click' ) ;
219
- } ) ;
220
- }
221
+ // Handle click on "Select all" control
222
+ $table_header . on ( 'click' , 'th.dt-checkboxes-select-all input[type="checkbox"]' , function ( e ) {
223
+ self . onClickSelectAll ( e , this ) ;
224
+ } ) ;
225
+
226
+ // Handle click on heading containing "Select all" control
227
+ $table_header . on ( 'click' , 'th.dt-checkboxes-select-all' , function ( e ) {
228
+ $ ( 'input[type="checkbox"]' , this ) . trigger ( 'click' ) ;
229
+ } ) ;
221
230
}
222
231
} ,
223
232
@@ -306,7 +315,7 @@ Checkboxes.prototype = {
306
315
}
307
316
} ) ;
308
317
}
309
-
318
+
310
319
if ( nodes . length ) {
311
320
// If Select extension is available
312
321
if ( DataTable . select ) {
0 commit comments