datatables.net-select 1.6.2 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,20 @@
1
- /*! Select for DataTables 1.6.2
1
+ /*! Select for DataTables 1.7.0
2
2
  * © SpryMedia Ltd - datatables.net/license/mit
3
3
  */
4
4
 
5
- import $ from 'jquery';
5
+ import jQuery from 'jquery';
6
6
  import DataTable from 'datatables.net';
7
7
 
8
+ // Allow reassignment of the $ variable
9
+ let $ = jQuery;
10
+
8
11
 
9
12
  // Version information for debugger
10
13
  DataTable.select = {};
11
14
 
12
- DataTable.select.version = '1.6.2';
15
+ DataTable.select.version = '1.7.0';
13
16
 
14
- DataTable.select.init = function ( dt ) {
17
+ DataTable.select.init = function (dt) {
15
18
  var ctx = dt.settings()[0];
16
19
 
17
20
  if (ctx._select) {
@@ -20,58 +23,55 @@ DataTable.select.init = function ( dt ) {
20
23
 
21
24
  var savedSelected = dt.state.loaded();
22
25
 
23
- var selectAndSave = function(e, settings, data) {
24
- if(data === null || data.select === undefined) {
26
+ var selectAndSave = function (e, settings, data) {
27
+ if (data === null || data.select === undefined) {
25
28
  return;
26
29
  }
27
30
 
28
31
  // Clear any currently selected rows, before restoring state
29
32
  // None will be selected on first initialisation
30
- if (dt.rows({selected: true}).any()) {
33
+ if (dt.rows({ selected: true }).any()) {
31
34
  dt.rows().deselect();
32
35
  }
33
36
  if (data.select.rows !== undefined) {
34
37
  dt.rows(data.select.rows).select();
35
38
  }
36
39
 
37
- if (dt.columns({selected: true}).any()) {
40
+ if (dt.columns({ selected: true }).any()) {
38
41
  dt.columns().deselect();
39
42
  }
40
43
  if (data.select.columns !== undefined) {
41
44
  dt.columns(data.select.columns).select();
42
45
  }
43
46
 
44
- if (dt.cells({selected: true}).any()) {
47
+ if (dt.cells({ selected: true }).any()) {
45
48
  dt.cells().deselect();
46
49
  }
47
50
  if (data.select.cells !== undefined) {
48
- for(var i = 0; i < data.select.cells.length; i++) {
51
+ for (var i = 0; i < data.select.cells.length; i++) {
49
52
  dt.cell(data.select.cells[i].row, data.select.cells[i].column).select();
50
53
  }
51
54
  }
52
55
 
53
56
  dt.state.save();
54
- }
55
-
56
- dt
57
- .on('stateSaveParams', function(e, settings, data) {
58
- data.select = {};
59
- data.select.rows = dt.rows({selected:true}).ids(true).toArray();
60
- data.select.columns = dt.columns({selected:true})[0];
61
- data.select.cells = dt.cells({selected:true})[0].map(function(coords) {
62
- return {row: dt.row(coords.row).id(true), column: coords.column}
63
- });
64
- })
57
+ };
58
+
59
+ dt.on('stateSaveParams', function (e, settings, data) {
60
+ data.select = {};
61
+ data.select.rows = dt.rows({ selected: true }).ids(true).toArray();
62
+ data.select.columns = dt.columns({ selected: true })[0];
63
+ data.select.cells = dt.cells({ selected: true })[0].map(function (coords) {
64
+ return { row: dt.row(coords.row).id(true), column: coords.column };
65
+ });
66
+ })
65
67
  .on('stateLoadParams', selectAndSave)
66
- .one('init', function() {
68
+ .one('init', function () {
67
69
  selectAndSave(undefined, undefined, savedSelected);
68
70
  });
69
71
 
70
72
  var init = ctx.oInit.select;
71
73
  var defaults = DataTable.defaults.select;
72
- var opts = init === undefined ?
73
- defaults :
74
- init;
74
+ var opts = init === undefined ? defaults : init;
75
75
 
76
76
  // Set defaults
77
77
  var items = 'row';
@@ -86,32 +86,32 @@ DataTable.select.init = function ( dt ) {
86
86
  ctx._select = {};
87
87
 
88
88
  // Initialisation customisations
89
- if ( opts === true ) {
89
+ if (opts === true) {
90
90
  style = 'os';
91
91
  setStyle = true;
92
92
  }
93
- else if ( typeof opts === 'string' ) {
93
+ else if (typeof opts === 'string') {
94
94
  style = opts;
95
95
  setStyle = true;
96
96
  }
97
- else if ( $.isPlainObject( opts ) ) {
98
- if ( opts.blurable !== undefined ) {
97
+ else if ($.isPlainObject(opts)) {
98
+ if (opts.blurable !== undefined) {
99
99
  blurable = opts.blurable;
100
100
  }
101
-
102
- if ( opts.toggleable !== undefined ) {
101
+
102
+ if (opts.toggleable !== undefined) {
103
103
  toggleable = opts.toggleable;
104
104
  }
105
105
 
106
- if ( opts.info !== undefined ) {
106
+ if (opts.info !== undefined) {
107
107
  info = opts.info;
108
108
  }
109
109
 
110
- if ( opts.items !== undefined ) {
110
+ if (opts.items !== undefined) {
111
111
  items = opts.items;
112
112
  }
113
113
 
114
- if ( opts.style !== undefined ) {
114
+ if (opts.style !== undefined) {
115
115
  style = opts.style;
116
116
  setStyle = true;
117
117
  }
@@ -120,40 +120,43 @@ DataTable.select.init = function ( dt ) {
120
120
  setStyle = true;
121
121
  }
122
122
 
123
- if ( opts.selector !== undefined ) {
123
+ if (opts.selector !== undefined) {
124
124
  selector = opts.selector;
125
125
  }
126
126
 
127
- if ( opts.className !== undefined ) {
127
+ if (opts.className !== undefined) {
128
128
  className = opts.className;
129
129
  }
130
130
  }
131
131
 
132
- dt.select.selector( selector );
133
- dt.select.items( items );
134
- dt.select.style( style );
135
- dt.select.blurable( blurable );
136
- dt.select.toggleable( toggleable );
137
- dt.select.info( info );
132
+ dt.select.selector(selector);
133
+ dt.select.items(items);
134
+ dt.select.style(style);
135
+ dt.select.blurable(blurable);
136
+ dt.select.toggleable(toggleable);
137
+ dt.select.info(info);
138
138
  ctx._select.className = className;
139
139
 
140
-
141
140
  // Sort table based on selected rows. Requires Select Datatables extension
142
- $.fn.dataTable.ext.order['select-checkbox'] = function ( settings, col ) {
143
- return this.api().column( col, {order: 'index'} ).nodes().map( function ( td ) {
144
- if ( settings._select.items === 'row' ) {
145
- return $( td ).parent().hasClass( settings._select.className );
146
- } else if ( settings._select.items === 'cell' ) {
147
- return $( td ).hasClass( settings._select.className );
148
- }
149
- return false;
150
- });
141
+ $.fn.dataTable.ext.order['select-checkbox'] = function (settings, col) {
142
+ return this.api()
143
+ .column(col, { order: 'index' })
144
+ .nodes()
145
+ .map(function (td) {
146
+ if (settings._select.items === 'row') {
147
+ return $(td).parent().hasClass(settings._select.className);
148
+ }
149
+ else if (settings._select.items === 'cell') {
150
+ return $(td).hasClass(settings._select.className);
151
+ }
152
+ return false;
153
+ });
151
154
  };
152
155
 
153
156
  // If the init options haven't enabled select, but there is a selectable
154
157
  // class name, then enable
155
- if ( ! setStyle && $( dt.table().node() ).hasClass( 'selectable' ) ) {
156
- dt.select.style( 'os' );
158
+ if (!setStyle && $(dt.table().node()).hasClass('selectable')) {
159
+ dt.select.style('os');
157
160
  }
158
161
  };
159
162
 
@@ -221,7 +224,6 @@ handler that will select the items using the API methods.
221
224
 
222
225
  */
223
226
 
224
-
225
227
  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
226
228
  * Local functions
227
229
  */
@@ -234,84 +236,87 @@ handler that will select the items using the API methods.
234
236
  * in the visible grid rather than by index in sequence. For example, if you
235
237
  * click first in cell 1-1 and then shift click in 2-2 - cells 1-2 and 2-1
236
238
  * should also be selected (and not 1-3, 1-4. etc)
237
- *
239
+ *
238
240
  * @param {DataTable.Api} dt DataTable
239
241
  * @param {object} idx Cell index to select to
240
242
  * @param {object} last Cell index to select from
241
243
  * @private
242
244
  */
243
- function cellRange( dt, idx, last )
244
- {
245
+ function cellRange(dt, idx, last) {
245
246
  var indexes;
246
247
  var columnIndexes;
247
248
  var rowIndexes;
248
- var selectColumns = function ( start, end ) {
249
- if ( start > end ) {
249
+ var selectColumns = function (start, end) {
250
+ if (start > end) {
250
251
  var tmp = end;
251
252
  end = start;
252
253
  start = tmp;
253
254
  }
254
-
255
+
255
256
  var record = false;
256
- return dt.columns( ':visible' ).indexes().filter( function (i) {
257
- if ( i === start ) {
258
- record = true;
259
- }
260
-
261
- if ( i === end ) { // not else if, as start might === end
262
- record = false;
263
- return true;
264
- }
257
+ return dt
258
+ .columns(':visible')
259
+ .indexes()
260
+ .filter(function (i) {
261
+ if (i === start) {
262
+ record = true;
263
+ }
265
264
 
266
- return record;
267
- } );
265
+ if (i === end) {
266
+ // not else if, as start might === end
267
+ record = false;
268
+ return true;
269
+ }
270
+
271
+ return record;
272
+ });
268
273
  };
269
274
 
270
- var selectRows = function ( start, end ) {
271
- var indexes = dt.rows( { search: 'applied' } ).indexes();
275
+ var selectRows = function (start, end) {
276
+ var indexes = dt.rows({ search: 'applied' }).indexes();
272
277
 
273
278
  // Which comes first - might need to swap
274
- if ( indexes.indexOf( start ) > indexes.indexOf( end ) ) {
279
+ if (indexes.indexOf(start) > indexes.indexOf(end)) {
275
280
  var tmp = end;
276
281
  end = start;
277
282
  start = tmp;
278
283
  }
279
284
 
280
285
  var record = false;
281
- return indexes.filter( function (i) {
282
- if ( i === start ) {
286
+ return indexes.filter(function (i) {
287
+ if (i === start) {
283
288
  record = true;
284
289
  }
285
-
286
- if ( i === end ) {
290
+
291
+ if (i === end) {
287
292
  record = false;
288
293
  return true;
289
294
  }
290
295
 
291
296
  return record;
292
- } );
297
+ });
293
298
  };
294
299
 
295
- if ( ! dt.cells( { selected: true } ).any() && ! last ) {
300
+ if (!dt.cells({ selected: true }).any() && !last) {
296
301
  // select from the top left cell to this one
297
- columnIndexes = selectColumns( 0, idx.column );
298
- rowIndexes = selectRows( 0 , idx.row );
302
+ columnIndexes = selectColumns(0, idx.column);
303
+ rowIndexes = selectRows(0, idx.row);
299
304
  }
300
305
  else {
301
306
  // Get column indexes between old and new
302
- columnIndexes = selectColumns( last.column, idx.column );
303
- rowIndexes = selectRows( last.row , idx.row );
307
+ columnIndexes = selectColumns(last.column, idx.column);
308
+ rowIndexes = selectRows(last.row, idx.row);
304
309
  }
305
310
 
306
- indexes = dt.cells( rowIndexes, columnIndexes ).flatten();
311
+ indexes = dt.cells(rowIndexes, columnIndexes).flatten();
307
312
 
308
- if ( ! dt.cells( idx, { selected: true } ).any() ) {
313
+ if (!dt.cells(idx, { selected: true }).any()) {
309
314
  // Select range
310
- dt.cells( indexes ).select();
315
+ dt.cells(indexes).select();
311
316
  }
312
317
  else {
313
318
  // Deselect range
314
- dt.cells( indexes ).deselect();
319
+ dt.cells(indexes).deselect();
315
320
  }
316
321
  }
317
322
 
@@ -321,17 +326,16 @@ function cellRange( dt, idx, last )
321
326
  * @param {DataTable.Api} dt DataTable to remove events from
322
327
  * @private
323
328
  */
324
- function disableMouseSelection( dt )
325
- {
329
+ function disableMouseSelection(dt) {
326
330
  var ctx = dt.settings()[0];
327
331
  var selector = ctx._select.selector;
328
332
 
329
- $( dt.table().container() )
330
- .off( 'mousedown.dtSelect', selector )
331
- .off( 'mouseup.dtSelect', selector )
332
- .off( 'click.dtSelect', selector );
333
+ $(dt.table().container())
334
+ .off('mousedown.dtSelect', selector)
335
+ .off('mouseup.dtSelect', selector)
336
+ .off('click.dtSelect', selector);
333
337
 
334
- $('body').off( 'click.dtSelect' + _safeId(dt.table().node()) );
338
+ $('body').off('click.dtSelect' + _safeId(dt.table().node()));
335
339
  }
336
340
 
337
341
  /**
@@ -340,47 +344,49 @@ function disableMouseSelection( dt )
340
344
  * @param {DataTable.Api} dt DataTable to remove events from
341
345
  * @private
342
346
  */
343
- function enableMouseSelection ( dt )
344
- {
345
- var container = $( dt.table().container() );
347
+ function enableMouseSelection(dt) {
348
+ var container = $(dt.table().container());
346
349
  var ctx = dt.settings()[0];
347
350
  var selector = ctx._select.selector;
348
351
  var matchSelection;
349
352
 
350
353
  container
351
- .on( 'mousedown.dtSelect', selector, function(e) {
354
+ .on('mousedown.dtSelect', selector, function (e) {
352
355
  // Disallow text selection for shift clicking on the table so multi
353
356
  // element selection doesn't look terrible!
354
- if ( e.shiftKey || e.metaKey || e.ctrlKey ) {
357
+ if (e.shiftKey || e.metaKey || e.ctrlKey) {
355
358
  container
356
- .css( '-moz-user-select', 'none' )
359
+ .css('-moz-user-select', 'none')
357
360
  .one('selectstart.dtSelect', selector, function () {
358
361
  return false;
359
- } );
362
+ });
360
363
  }
361
364
 
362
- if ( window.getSelection ) {
365
+ if (window.getSelection) {
363
366
  matchSelection = window.getSelection();
364
367
  }
365
- } )
366
- .on( 'mouseup.dtSelect', selector, function() {
368
+ })
369
+ .on('mouseup.dtSelect', selector, function () {
367
370
  // Allow text selection to occur again, Mozilla style (tested in FF
368
371
  // 35.0.1 - still required)
369
- container.css( '-moz-user-select', '' );
370
- } )
371
- .on( 'click.dtSelect', selector, function ( e ) {
372
+ container.css('-moz-user-select', '');
373
+ })
374
+ .on('click.dtSelect', selector, function (e) {
372
375
  var items = dt.select.items();
373
376
  var idx;
374
377
 
375
378
  // If text was selected (click and drag), then we shouldn't change
376
379
  // the row's selected state
377
- if ( matchSelection ) {
380
+ if (matchSelection) {
378
381
  var selection = window.getSelection();
379
382
 
380
383
  // If the element that contains the selection is not in the table, we can ignore it
381
384
  // This can happen if the developer selects text from the click event
382
- if ( ! selection.anchorNode || $(selection.anchorNode).closest('table')[0] === dt.table().node() ) {
383
- if ( selection !== matchSelection ) {
385
+ if (
386
+ !selection.anchorNode ||
387
+ $(selection.anchorNode).closest('table')[0] === dt.table().node()
388
+ ) {
389
+ if (selection !== matchSelection) {
384
390
  return;
385
391
  }
386
392
  }
@@ -390,71 +396,71 @@ function enableMouseSelection ( dt )
390
396
  var wrapperClass = dt.settings()[0].oClasses.sWrapper.trim().replace(/ +/g, '.');
391
397
 
392
398
  // Ignore clicks inside a sub-table
393
- if ( $(e.target).closest('div.'+wrapperClass)[0] != dt.table().container() ) {
399
+ if ($(e.target).closest('div.' + wrapperClass)[0] != dt.table().container()) {
394
400
  return;
395
401
  }
396
402
 
397
- var cell = dt.cell( $(e.target).closest('td, th') );
403
+ var cell = dt.cell($(e.target).closest('td, th'));
398
404
 
399
405
  // Check the cell actually belongs to the host DataTable (so child
400
406
  // rows, etc, are ignored)
401
- if ( ! cell.any() ) {
407
+ if (!cell.any()) {
402
408
  return;
403
409
  }
404
410
 
405
411
  var event = $.Event('user-select.dt');
406
- eventTrigger( dt, event, [ items, cell, e ] );
412
+ eventTrigger(dt, event, [items, cell, e]);
407
413
 
408
- if ( event.isDefaultPrevented() ) {
414
+ if (event.isDefaultPrevented()) {
409
415
  return;
410
416
  }
411
417
 
412
418
  var cellIndex = cell.index();
413
- if ( items === 'row' ) {
419
+ if (items === 'row') {
414
420
  idx = cellIndex.row;
415
- typeSelect( e, dt, ctx, 'row', idx );
421
+ typeSelect(e, dt, ctx, 'row', idx);
416
422
  }
417
- else if ( items === 'column' ) {
423
+ else if (items === 'column') {
418
424
  idx = cell.index().column;
419
- typeSelect( e, dt, ctx, 'column', idx );
425
+ typeSelect(e, dt, ctx, 'column', idx);
420
426
  }
421
- else if ( items === 'cell' ) {
427
+ else if (items === 'cell') {
422
428
  idx = cell.index();
423
- typeSelect( e, dt, ctx, 'cell', idx );
429
+ typeSelect(e, dt, ctx, 'cell', idx);
424
430
  }
425
431
 
426
432
  ctx._select_lastCell = cellIndex;
427
- } );
433
+ });
428
434
 
429
435
  // Blurable
430
- $('body').on( 'click.dtSelect' + _safeId(dt.table().node()), function ( e ) {
431
- if ( ctx._select.blurable ) {
436
+ $('body').on('click.dtSelect' + _safeId(dt.table().node()), function (e) {
437
+ if (ctx._select.blurable) {
432
438
  // If the click was inside the DataTables container, don't blur
433
- if ( $(e.target).parents().filter( dt.table().container() ).length ) {
439
+ if ($(e.target).parents().filter(dt.table().container()).length) {
434
440
  return;
435
441
  }
436
442
 
437
443
  // Ignore elements which have been removed from the DOM (i.e. paging
438
444
  // buttons)
439
- if ( $(e.target).parents('html').length === 0 ) {
440
- return;
445
+ if ($(e.target).parents('html').length === 0) {
446
+ return;
441
447
  }
442
448
 
443
449
  // Don't blur in Editor form
444
- if ( $(e.target).parents('div.DTE').length ) {
450
+ if ($(e.target).parents('div.DTE').length) {
445
451
  return;
446
452
  }
447
453
 
448
454
  var event = $.Event('select-blur.dt');
449
- eventTrigger( dt, event, [ e.target, e ] );
455
+ eventTrigger(dt, event, [e.target, e]);
450
456
 
451
- if ( event.isDefaultPrevented() ) {
457
+ if (event.isDefaultPrevented()) {
452
458
  return;
453
459
  }
454
460
 
455
- clear( ctx, true );
461
+ clear(ctx, true);
456
462
  }
457
- } );
463
+ });
458
464
  }
459
465
 
460
466
  /**
@@ -467,70 +473,72 @@ function enableMouseSelection ( dt )
467
473
  * triggering
468
474
  * @private
469
475
  */
470
- function eventTrigger ( api, type, args, any )
471
- {
472
- if ( any && ! api.flatten().length ) {
476
+ function eventTrigger(api, type, args, any) {
477
+ if (any && !api.flatten().length) {
473
478
  return;
474
479
  }
475
480
 
476
- if ( typeof type === 'string' ) {
477
- type = type +'.dt';
481
+ if (typeof type === 'string') {
482
+ type = type + '.dt';
478
483
  }
479
484
 
480
- args.unshift( api );
485
+ args.unshift(api);
481
486
 
482
- $(api.table().node()).trigger( type, args );
487
+ $(api.table().node()).trigger(type, args);
483
488
  }
484
489
 
485
490
  /**
486
491
  * Update the information element of the DataTable showing information about the
487
492
  * items selected. This is done by adding tags to the existing text
488
- *
493
+ *
489
494
  * @param {DataTable.Api} api DataTable to update
490
495
  * @private
491
496
  */
492
- function info ( api )
493
- {
497
+ function info(api) {
494
498
  var ctx = api.settings()[0];
495
499
 
496
- if ( ! ctx._select.info || ! ctx.aanFeatures.i ) {
500
+ if (!ctx._select.info || !ctx.aanFeatures.i) {
497
501
  return;
498
502
  }
499
503
 
500
- if ( api.select.style() === 'api' ) {
504
+ if (api.select.style() === 'api') {
501
505
  return;
502
506
  }
503
507
 
504
- var rows = api.rows( { selected: true } ).flatten().length;
505
- var columns = api.columns( { selected: true } ).flatten().length;
506
- var cells = api.cells( { selected: true } ).flatten().length;
507
-
508
- var add = function ( el, name, num ) {
509
- el.append( $('<span class="select-item"/>').append( api.i18n(
510
- 'select.'+name+'s',
511
- { _: '%d '+name+'s selected', 0: '', 1: '1 '+name+' selected' },
512
- num
513
- ) ) );
508
+ var rows = api.rows({ selected: true }).flatten().length;
509
+ var columns = api.columns({ selected: true }).flatten().length;
510
+ var cells = api.cells({ selected: true }).flatten().length;
511
+
512
+ var add = function (el, name, num) {
513
+ el.append(
514
+ $('<span class="select-item"/>').append(
515
+ api.i18n(
516
+ 'select.' + name + 's',
517
+ { _: '%d ' + name + 's selected', 0: '', 1: '1 ' + name + ' selected' },
518
+ num
519
+ )
520
+ )
521
+ );
514
522
  };
515
523
 
516
524
  // Internal knowledge of DataTables to loop over all information elements
517
- $.each( ctx.aanFeatures.i, function ( i, el ) {
525
+ $.each(ctx.aanFeatures.i, function (i, el) {
518
526
  el = $(el);
519
527
 
520
- var output = $('<span class="select-info"/>');
521
- add( output, 'row', rows );
522
- add( output, 'column', columns );
523
- add( output, 'cell', cells );
528
+ var output = $('<span class="select-info"/>');
529
+ add(output, 'row', rows);
530
+ add(output, 'column', columns);
531
+ add(output, 'cell', cells);
524
532
 
525
533
  var exisiting = el.children('span.select-info');
526
- if ( exisiting.length ) {
534
+ if (exisiting.length) {
527
535
  exisiting.remove();
528
536
  }
529
537
 
530
- if ( output.text() !== '' ) {
531
- el.append( output );
538
+ if (output.text() !== '') {
539
+ el.append(output);
532
540
  }
533
- } );
541
+ });
534
542
  }
535
543
 
536
544
  /**
@@ -543,41 +551,44 @@ function info ( api )
543
551
  * @param {DataTable.settings} ctx Settings object to operate on
544
552
  * @private
545
553
  */
546
- function init ( ctx ) {
547
- var api = new DataTable.Api( ctx );
554
+ function init(ctx) {
555
+ var api = new DataTable.Api(ctx);
548
556
  ctx._select_init = true;
549
557
 
550
558
  // Row callback so that classes can be added to rows and cells if the item
551
559
  // was selected before the element was created. This will happen with the
552
560
  // `deferRender` option enabled.
553
- //
561
+ //
554
562
  // This method of attaching to `aoRowCreatedCallback` is a hack until
555
563
  // DataTables has proper events for row manipulation If you are reviewing
556
564
  // this code to create your own plug-ins, please do not do this!
557
- ctx.aoRowCreatedCallback.push( {
558
- fn: function ( row, data, index ) {
565
+ ctx.aoRowCreatedCallback.push({
566
+ fn: function (row, data, index) {
559
567
  var i, ien;
560
- var d = ctx.aoData[ index ];
568
+ var d = ctx.aoData[index];
561
569
 
562
570
  // Row
563
- if ( d._select_selected ) {
564
- $( row ).addClass( ctx._select.className );
571
+ if (d._select_selected) {
572
+ $(row).addClass(ctx._select.className);
565
573
  }
566
574
 
567
575
  // Cells and columns - if separated out, we would need to do two
568
576
  // loops, so it makes sense to combine them into a single one
569
- for ( i=0, ien=ctx.aoColumns.length ; i<ien ; i++ ) {
570
- if ( ctx.aoColumns[i]._select_selected || (d._selected_cells && d._selected_cells[i]) ) {
571
- $(d.anCells[i]).addClass( ctx._select.className );
577
+ for (i = 0, ien = ctx.aoColumns.length; i < ien; i++) {
578
+ if (
579
+ ctx.aoColumns[i]._select_selected ||
580
+ (d._selected_cells && d._selected_cells[i])
581
+ ) {
582
+ $(d.anCells[i]).addClass(ctx._select.className);
572
583
  }
573
584
  }
574
585
  },
575
586
  sName: 'select-deferRender'
576
- } );
587
+ });
577
588
 
578
589
  // On Ajax reload we want to reselect all rows which are currently selected,
579
590
  // if there is an rowId (i.e. a unique value to identify each row with)
580
- api.on( 'preXhr.dt.dtSelect', function (e, settings) {
591
+ api.on('preXhr.dt.dtSelect', function (e, settings) {
581
592
  if (settings !== api.settings()[0]) {
582
593
  // Not triggered by our DataTable!
583
594
  return;
@@ -585,47 +596,52 @@ function init ( ctx ) {
585
596
 
586
597
  // note that column selection doesn't need to be cached and then
587
598
  // reselected, as they are already selected
588
- var rows = api.rows( { selected: true } ).ids( true ).filter( function ( d ) {
589
- return d !== undefined;
590
- } );
591
-
592
- var cells = api.cells( { selected: true } ).eq(0).map( function ( cellIdx ) {
593
- var id = api.row( cellIdx.row ).id( true );
594
- return id ?
595
- { row: id, column: cellIdx.column } :
596
- undefined;
597
- } ).filter( function ( d ) {
598
- return d !== undefined;
599
- } );
599
+ var rows = api
600
+ .rows({ selected: true })
601
+ .ids(true)
602
+ .filter(function (d) {
603
+ return d !== undefined;
604
+ });
605
+
606
+ var cells = api
607
+ .cells({ selected: true })
608
+ .eq(0)
609
+ .map(function (cellIdx) {
610
+ var id = api.row(cellIdx.row).id(true);
611
+ return id ? { row: id, column: cellIdx.column } : undefined;
612
+ })
613
+ .filter(function (d) {
614
+ return d !== undefined;
615
+ });
600
616
 
601
617
  // On the next draw, reselect the currently selected items
602
- api.one( 'draw.dt.dtSelect', function () {
603
- api.rows( rows ).select();
618
+ api.one('draw.dt.dtSelect', function () {
619
+ api.rows(rows).select();
604
620
 
605
621
  // `cells` is not a cell index selector, so it needs a loop
606
- if ( cells.any() ) {
607
- cells.each( function ( id ) {
608
- api.cells( id.row, id.column ).select();
609
- } );
622
+ if (cells.any()) {
623
+ cells.each(function (id) {
624
+ api.cells(id.row, id.column).select();
625
+ });
610
626
  }
611
- } );
612
- } );
627
+ });
628
+ });
613
629
 
614
630
  // Update the table information element with selected item summary
615
- api.on( 'draw.dtSelect.dt select.dtSelect.dt deselect.dtSelect.dt info.dt', function () {
616
- info( api );
631
+ api.on('draw.dtSelect.dt select.dtSelect.dt deselect.dtSelect.dt info.dt', function () {
632
+ info(api);
617
633
  api.state.save();
618
- } );
634
+ });
619
635
 
620
636
  // Clean up and release
621
- api.on( 'destroy.dtSelect', function () {
637
+ api.on('destroy.dtSelect', function () {
622
638
  // Remove class directly rather than calling deselect - which would trigger events
623
- $(api.rows({selected: true}).nodes()).removeClass(api.settings()[0]._select.className);
639
+ $(api.rows({ selected: true }).nodes()).removeClass(api.settings()[0]._select.className);
624
640
 
625
- disableMouseSelection( api );
626
- api.off( '.dtSelect' );
641
+ disableMouseSelection(api);
642
+ api.off('.dtSelect');
627
643
  $('body').off('.dtSelect' + _safeId(api.table().node()));
628
- } );
644
+ });
629
645
  }
630
646
 
631
647
  /**
@@ -638,38 +654,37 @@ function init ( ctx ) {
638
654
  * @param {object} last Item index to select from
639
655
  * @private
640
656
  */
641
- function rowColumnRange( dt, type, idx, last )
642
- {
657
+ function rowColumnRange(dt, type, idx, last) {
643
658
  // Add a range of rows from the last selected row to this one
644
- var indexes = dt[type+'s']( { search: 'applied' } ).indexes();
645
- var idx1 = $.inArray( last, indexes );
646
- var idx2 = $.inArray( idx, indexes );
659
+ var indexes = dt[type + 's']({ search: 'applied' }).indexes();
660
+ var idx1 = $.inArray(last, indexes);
661
+ var idx2 = $.inArray(idx, indexes);
647
662
 
648
- if ( ! dt[type+'s']( { selected: true } ).any() && idx1 === -1 ) {
663
+ if (!dt[type + 's']({ selected: true }).any() && idx1 === -1) {
649
664
  // select from top to here - slightly odd, but both Windows and Mac OS
650
665
  // do this
651
- indexes.splice( $.inArray( idx, indexes )+1, indexes.length );
666
+ indexes.splice($.inArray(idx, indexes) + 1, indexes.length);
652
667
  }
653
668
  else {
654
669
  // reverse so we can shift click 'up' as well as down
655
- if ( idx1 > idx2 ) {
670
+ if (idx1 > idx2) {
656
671
  var tmp = idx2;
657
672
  idx2 = idx1;
658
673
  idx1 = tmp;
659
674
  }
660
675
 
661
- indexes.splice( idx2+1, indexes.length );
662
- indexes.splice( 0, idx1 );
676
+ indexes.splice(idx2 + 1, indexes.length);
677
+ indexes.splice(0, idx1);
663
678
  }
664
679
 
665
- if ( ! dt[type]( idx, { selected: true } ).any() ) {
680
+ if (!dt[type](idx, { selected: true }).any()) {
666
681
  // Select range
667
- dt[type+'s']( indexes ).select();
682
+ dt[type + 's'](indexes).select();
668
683
  }
669
684
  else {
670
685
  // Deselect range - need to keep the clicked on row selected
671
- indexes.splice( $.inArray( idx, indexes ), 1 );
672
- dt[type+'s']( indexes ).deselect();
686
+ indexes.splice($.inArray(idx, indexes), 1);
687
+ dt[type + 's'](indexes).deselect();
673
688
  }
674
689
  }
675
690
 
@@ -681,14 +696,13 @@ function rowColumnRange( dt, type, idx, last )
681
696
  * of selection style
682
697
  * @private
683
698
  */
684
- function clear( ctx, force )
685
- {
686
- if ( force || ctx._select.style === 'single' ) {
687
- var api = new DataTable.Api( ctx );
688
-
689
- api.rows( { selected: true } ).deselect();
690
- api.columns( { selected: true } ).deselect();
691
- api.cells( { selected: true } ).deselect();
699
+ function clear(ctx, force) {
700
+ if (force || ctx._select.style === 'single') {
701
+ var api = new DataTable.Api(ctx);
702
+
703
+ api.rows({ selected: true }).deselect();
704
+ api.columns({ selected: true }).deselect();
705
+ api.cells({ selected: true }).deselect();
692
706
  }
693
707
  }
694
708
 
@@ -702,72 +716,74 @@ function clear( ctx, force )
702
716
  * @param {int|object} idx Index of the item to select
703
717
  * @private
704
718
  */
705
- function typeSelect ( e, dt, ctx, type, idx )
706
- {
719
+ function typeSelect(e, dt, ctx, type, idx) {
707
720
  var style = dt.select.style();
708
721
  var toggleable = dt.select.toggleable();
709
- var isSelected = dt[type]( idx, { selected: true } ).any();
710
-
711
- if ( isSelected && ! toggleable ) {
722
+ var isSelected = dt[type](idx, { selected: true }).any();
723
+
724
+ if (isSelected && !toggleable) {
712
725
  return;
713
726
  }
714
727
 
715
- if ( style === 'os' ) {
716
- if ( e.ctrlKey || e.metaKey ) {
728
+ if (style === 'os') {
729
+ if (e.ctrlKey || e.metaKey) {
717
730
  // Add or remove from the selection
718
- dt[type]( idx ).select( ! isSelected );
731
+ dt[type](idx).select(!isSelected);
719
732
  }
720
- else if ( e.shiftKey ) {
721
- if ( type === 'cell' ) {
722
- cellRange( dt, idx, ctx._select_lastCell || null );
733
+ else if (e.shiftKey) {
734
+ if (type === 'cell') {
735
+ cellRange(dt, idx, ctx._select_lastCell || null);
723
736
  }
724
737
  else {
725
- rowColumnRange( dt, type, idx, ctx._select_lastCell ?
726
- ctx._select_lastCell[type] :
727
- null
738
+ rowColumnRange(
739
+ dt,
740
+ type,
741
+ idx,
742
+ ctx._select_lastCell ? ctx._select_lastCell[type] : null
728
743
  );
729
744
  }
730
745
  }
731
746
  else {
732
747
  // No cmd or shift click - deselect if selected, or select
733
748
  // this row only
734
- var selected = dt[type+'s']( { selected: true } );
749
+ var selected = dt[type + 's']({ selected: true });
735
750
 
736
- if ( isSelected && selected.flatten().length === 1 ) {
737
- dt[type]( idx ).deselect();
751
+ if (isSelected && selected.flatten().length === 1) {
752
+ dt[type](idx).deselect();
738
753
  }
739
754
  else {
740
755
  selected.deselect();
741
- dt[type]( idx ).select();
756
+ dt[type](idx).select();
742
757
  }
743
758
  }
744
- } else if ( style == 'multi+shift' ) {
745
- if ( e.shiftKey ) {
746
- if ( type === 'cell' ) {
747
- cellRange( dt, idx, ctx._select_lastCell || null );
759
+ }
760
+ else if (style == 'multi+shift') {
761
+ if (e.shiftKey) {
762
+ if (type === 'cell') {
763
+ cellRange(dt, idx, ctx._select_lastCell || null);
748
764
  }
749
765
  else {
750
- rowColumnRange( dt, type, idx, ctx._select_lastCell ?
751
- ctx._select_lastCell[type] :
752
- null
766
+ rowColumnRange(
767
+ dt,
768
+ type,
769
+ idx,
770
+ ctx._select_lastCell ? ctx._select_lastCell[type] : null
753
771
  );
754
772
  }
755
773
  }
756
774
  else {
757
- dt[ type ]( idx ).select( ! isSelected );
775
+ dt[type](idx).select(!isSelected);
758
776
  }
759
777
  }
760
778
  else {
761
- dt[ type ]( idx ).select( ! isSelected );
779
+ dt[type](idx).select(!isSelected);
762
780
  }
763
781
  }
764
782
 
765
- function _safeId( node ) {
783
+ function _safeId(node) {
766
784
  return node.id.replace(/[^a-zA-Z0-9\-\_]/g, '-');
767
785
  }
768
786
 
769
-
770
-
771
787
  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
772
788
  * DataTables selectors
773
789
  */
@@ -775,56 +791,62 @@ function _safeId( node ) {
775
791
  // row and column are basically identical just assigned to different properties
776
792
  // and checking a different array, so we can dynamically create the functions to
777
793
  // reduce the code size
778
- $.each( [
779
- { type: 'row', prop: 'aoData' },
780
- { type: 'column', prop: 'aoColumns' }
781
- ], function ( i, o ) {
782
- DataTable.ext.selector[ o.type ].push( function ( settings, opts, indexes ) {
783
- var selected = opts.selected;
784
- var data;
785
- var out = [];
786
-
787
- if ( selected !== true && selected !== false ) {
788
- return indexes;
789
- }
794
+ $.each(
795
+ [
796
+ { type: 'row', prop: 'aoData' },
797
+ { type: 'column', prop: 'aoColumns' }
798
+ ],
799
+ function (i, o) {
800
+ DataTable.ext.selector[o.type].push(function (settings, opts, indexes) {
801
+ var selected = opts.selected;
802
+ var data;
803
+ var out = [];
804
+
805
+ if (selected !== true && selected !== false) {
806
+ return indexes;
807
+ }
790
808
 
791
- for ( var i=0, ien=indexes.length ; i<ien ; i++ ) {
792
- data = settings[ o.prop ][ indexes[i] ];
809
+ for (var i = 0, ien = indexes.length; i < ien; i++) {
810
+ data = settings[o.prop][indexes[i]];
793
811
 
794
- if ( (selected === true && data._select_selected === true) ||
795
- (selected === false && ! data._select_selected )
796
- ) {
797
- out.push( indexes[i] );
812
+ if (
813
+ (selected === true && data._select_selected === true) ||
814
+ (selected === false && !data._select_selected)
815
+ ) {
816
+ out.push(indexes[i]);
817
+ }
798
818
  }
799
- }
800
819
 
801
- return out;
802
- } );
803
- } );
820
+ return out;
821
+ });
822
+ }
823
+ );
804
824
 
805
- DataTable.ext.selector.cell.push( function ( settings, opts, cells ) {
825
+ DataTable.ext.selector.cell.push(function (settings, opts, cells) {
806
826
  var selected = opts.selected;
807
827
  var rowData;
808
828
  var out = [];
809
829
 
810
- if ( selected === undefined ) {
830
+ if (selected === undefined) {
811
831
  return cells;
812
832
  }
813
833
 
814
- for ( var i=0, ien=cells.length ; i<ien ; i++ ) {
815
- rowData = settings.aoData[ cells[i].row ];
834
+ for (var i = 0, ien = cells.length; i < ien; i++) {
835
+ rowData = settings.aoData[cells[i].row];
816
836
 
817
- if ( (selected === true && rowData._selected_cells && rowData._selected_cells[ cells[i].column ] === true) ||
818
- (selected === false && ( ! rowData._selected_cells || ! rowData._selected_cells[ cells[i].column ] ) )
837
+ if (
838
+ (selected === true &&
839
+ rowData._selected_cells &&
840
+ rowData._selected_cells[cells[i].column] === true) ||
841
+ (selected === false &&
842
+ (!rowData._selected_cells || !rowData._selected_cells[cells[i].column]))
819
843
  ) {
820
- out.push( cells[i] );
844
+ out.push(cells[i]);
821
845
  }
822
846
  }
823
847
 
824
848
  return out;
825
- } );
826
-
827
-
849
+ });
828
850
 
829
851
  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
830
852
  * DataTables API
@@ -837,67 +859,67 @@ DataTable.ext.selector.cell.push( function ( settings, opts, cells ) {
837
859
  var apiRegister = DataTable.Api.register;
838
860
  var apiRegisterPlural = DataTable.Api.registerPlural;
839
861
 
840
- apiRegister( 'select()', function () {
841
- return this.iterator( 'table', function ( ctx ) {
842
- DataTable.select.init( new DataTable.Api( ctx ) );
843
- } );
844
- } );
862
+ apiRegister('select()', function () {
863
+ return this.iterator('table', function (ctx) {
864
+ DataTable.select.init(new DataTable.Api(ctx));
865
+ });
866
+ });
845
867
 
846
- apiRegister( 'select.blurable()', function ( flag ) {
847
- if ( flag === undefined ) {
868
+ apiRegister('select.blurable()', function (flag) {
869
+ if (flag === undefined) {
848
870
  return this.context[0]._select.blurable;
849
871
  }
850
872
 
851
- return this.iterator( 'table', function ( ctx ) {
873
+ return this.iterator('table', function (ctx) {
852
874
  ctx._select.blurable = flag;
853
- } );
854
- } );
875
+ });
876
+ });
855
877
 
856
- apiRegister( 'select.toggleable()', function ( flag ) {
857
- if ( flag === undefined ) {
878
+ apiRegister('select.toggleable()', function (flag) {
879
+ if (flag === undefined) {
858
880
  return this.context[0]._select.toggleable;
859
881
  }
860
882
 
861
- return this.iterator( 'table', function ( ctx ) {
883
+ return this.iterator('table', function (ctx) {
862
884
  ctx._select.toggleable = flag;
863
- } );
864
- } );
885
+ });
886
+ });
865
887
 
866
- apiRegister( 'select.info()', function ( flag ) {
867
- if ( flag === undefined ) {
888
+ apiRegister('select.info()', function (flag) {
889
+ if (flag === undefined) {
868
890
  return this.context[0]._select.info;
869
891
  }
870
892
 
871
- return this.iterator( 'table', function ( ctx ) {
893
+ return this.iterator('table', function (ctx) {
872
894
  ctx._select.info = flag;
873
- } );
874
- } );
895
+ });
896
+ });
875
897
 
876
- apiRegister( 'select.items()', function ( items ) {
877
- if ( items === undefined ) {
898
+ apiRegister('select.items()', function (items) {
899
+ if (items === undefined) {
878
900
  return this.context[0]._select.items;
879
901
  }
880
902
 
881
- return this.iterator( 'table', function ( ctx ) {
903
+ return this.iterator('table', function (ctx) {
882
904
  ctx._select.items = items;
883
905
 
884
- eventTrigger( new DataTable.Api( ctx ), 'selectItems', [ items ] );
885
- } );
886
- } );
906
+ eventTrigger(new DataTable.Api(ctx), 'selectItems', [items]);
907
+ });
908
+ });
887
909
 
888
910
  // Takes effect from the _next_ selection. None disables future selection, but
889
911
  // does not clear the current selection. Use the `deselect` methods for that
890
- apiRegister( 'select.style()', function ( style ) {
891
- if ( style === undefined ) {
912
+ apiRegister('select.style()', function (style) {
913
+ if (style === undefined) {
892
914
  return this.context[0]._select.style;
893
915
  }
894
916
 
895
- return this.iterator( 'table', function ( ctx ) {
896
- if ( ! ctx._select ) {
897
- DataTable.select.init( new DataTable.Api(ctx) );
917
+ return this.iterator('table', function (ctx) {
918
+ if (!ctx._select) {
919
+ DataTable.select.init(new DataTable.Api(ctx));
898
920
  }
899
921
 
900
- if ( ! ctx._select_init ) {
922
+ if (!ctx._select_init) {
901
923
  init(ctx);
902
924
  }
903
925
 
@@ -905,144 +927,132 @@ apiRegister( 'select.style()', function ( style ) {
905
927
 
906
928
  // Add / remove mouse event handlers. They aren't required when only
907
929
  // API selection is available
908
- var dt = new DataTable.Api( ctx );
909
- disableMouseSelection( dt );
910
-
911
- if ( style !== 'api' ) {
912
- enableMouseSelection( dt );
930
+ var dt = new DataTable.Api(ctx);
931
+ disableMouseSelection(dt);
932
+
933
+ if (style !== 'api') {
934
+ enableMouseSelection(dt);
913
935
  }
914
936
 
915
- eventTrigger( new DataTable.Api( ctx ), 'selectStyle', [ style ] );
916
- } );
917
- } );
937
+ eventTrigger(new DataTable.Api(ctx), 'selectStyle', [style]);
938
+ });
939
+ });
918
940
 
919
- apiRegister( 'select.selector()', function ( selector ) {
920
- if ( selector === undefined ) {
941
+ apiRegister('select.selector()', function (selector) {
942
+ if (selector === undefined) {
921
943
  return this.context[0]._select.selector;
922
944
  }
923
945
 
924
- return this.iterator( 'table', function ( ctx ) {
925
- disableMouseSelection( new DataTable.Api( ctx ) );
946
+ return this.iterator('table', function (ctx) {
947
+ disableMouseSelection(new DataTable.Api(ctx));
926
948
 
927
949
  ctx._select.selector = selector;
928
950
 
929
- if ( ctx._select.style !== 'api' ) {
930
- enableMouseSelection( new DataTable.Api( ctx ) );
951
+ if (ctx._select.style !== 'api') {
952
+ enableMouseSelection(new DataTable.Api(ctx));
931
953
  }
932
- } );
933
- } );
934
-
954
+ });
955
+ });
935
956
 
936
-
937
- apiRegisterPlural( 'rows().select()', 'row().select()', function ( select ) {
957
+ apiRegisterPlural('rows().select()', 'row().select()', function (select) {
938
958
  var api = this;
939
959
 
940
- if ( select === false ) {
960
+ if (select === false) {
941
961
  return this.deselect();
942
962
  }
943
963
 
944
- this.iterator( 'row', function ( ctx, idx ) {
945
- clear( ctx );
964
+ this.iterator('row', function (ctx, idx) {
965
+ clear(ctx);
946
966
 
947
- ctx.aoData[ idx ]._select_selected = true;
948
- $( ctx.aoData[ idx ].nTr ).addClass( ctx._select.className );
949
- } );
967
+ ctx.aoData[idx]._select_selected = true;
968
+ $(ctx.aoData[idx].nTr).addClass(ctx._select.className);
969
+ });
950
970
 
951
- this.iterator( 'table', function ( ctx, i ) {
952
- eventTrigger( api, 'select', [ 'row', api[i] ], true );
953
- } );
971
+ this.iterator('table', function (ctx, i) {
972
+ eventTrigger(api, 'select', ['row', api[i]], true);
973
+ });
954
974
 
955
975
  return this;
956
- } );
976
+ });
957
977
 
958
- apiRegister( 'row().selected()', function () {
978
+ apiRegister('row().selected()', function () {
959
979
  var ctx = this.context[0];
960
980
 
961
- if (
962
- ctx &&
963
- this.length &&
964
- ctx.aoData[this[0]] &&
965
- ctx.aoData[this[0]]._select_selected
966
- ) {
981
+ if (ctx && this.length && ctx.aoData[this[0]] && ctx.aoData[this[0]]._select_selected) {
967
982
  return true;
968
983
  }
969
984
 
970
985
  return false;
971
- } );
986
+ });
972
987
 
973
- apiRegisterPlural( 'columns().select()', 'column().select()', function ( select ) {
988
+ apiRegisterPlural('columns().select()', 'column().select()', function (select) {
974
989
  var api = this;
975
990
 
976
- if ( select === false ) {
991
+ if (select === false) {
977
992
  return this.deselect();
978
993
  }
979
994
 
980
- this.iterator( 'column', function ( ctx, idx ) {
981
- clear( ctx );
995
+ this.iterator('column', function (ctx, idx) {
996
+ clear(ctx);
982
997
 
983
- ctx.aoColumns[ idx ]._select_selected = true;
998
+ ctx.aoColumns[idx]._select_selected = true;
984
999
 
985
- var column = new DataTable.Api( ctx ).column( idx );
1000
+ var column = new DataTable.Api(ctx).column(idx);
986
1001
 
987
- $( column.header() ).addClass( ctx._select.className );
988
- $( column.footer() ).addClass( ctx._select.className );
1002
+ $(column.header()).addClass(ctx._select.className);
1003
+ $(column.footer()).addClass(ctx._select.className);
989
1004
 
990
- column.nodes().to$().addClass( ctx._select.className );
991
- } );
1005
+ column.nodes().to$().addClass(ctx._select.className);
1006
+ });
992
1007
 
993
- this.iterator( 'table', function ( ctx, i ) {
994
- eventTrigger( api, 'select', [ 'column', api[i] ], true );
995
- } );
1008
+ this.iterator('table', function (ctx, i) {
1009
+ eventTrigger(api, 'select', ['column', api[i]], true);
1010
+ });
996
1011
 
997
1012
  return this;
998
- } );
1013
+ });
999
1014
 
1000
- apiRegister( 'column().selected()', function () {
1015
+ apiRegister('column().selected()', function () {
1001
1016
  var ctx = this.context[0];
1002
1017
 
1003
- if (
1004
- ctx &&
1005
- this.length &&
1006
- ctx.aoColumns[this[0]] &&
1007
- ctx.aoColumns[this[0]]._select_selected
1008
- ) {
1018
+ if (ctx && this.length && ctx.aoColumns[this[0]] && ctx.aoColumns[this[0]]._select_selected) {
1009
1019
  return true;
1010
1020
  }
1011
1021
 
1012
1022
  return false;
1013
- } );
1023
+ });
1014
1024
 
1015
- apiRegisterPlural( 'cells().select()', 'cell().select()', function ( select ) {
1025
+ apiRegisterPlural('cells().select()', 'cell().select()', function (select) {
1016
1026
  var api = this;
1017
1027
 
1018
- if ( select === false ) {
1028
+ if (select === false) {
1019
1029
  return this.deselect();
1020
1030
  }
1021
1031
 
1022
- this.iterator( 'cell', function ( ctx, rowIdx, colIdx ) {
1023
- clear( ctx );
1032
+ this.iterator('cell', function (ctx, rowIdx, colIdx) {
1033
+ clear(ctx);
1024
1034
 
1025
- var data = ctx.aoData[ rowIdx ];
1035
+ var data = ctx.aoData[rowIdx];
1026
1036
 
1027
- if ( data._selected_cells === undefined ) {
1037
+ if (data._selected_cells === undefined) {
1028
1038
  data._selected_cells = [];
1029
1039
  }
1030
1040
 
1031
- data._selected_cells[ colIdx ] = true;
1041
+ data._selected_cells[colIdx] = true;
1032
1042
 
1033
- if ( data.anCells ) {
1034
- $( data.anCells[ colIdx ] ).addClass( ctx._select.className );
1043
+ if (data.anCells) {
1044
+ $(data.anCells[colIdx]).addClass(ctx._select.className);
1035
1045
  }
1036
- } );
1046
+ });
1037
1047
 
1038
- this.iterator( 'table', function ( ctx, i ) {
1039
- eventTrigger( api, 'select', [ 'cell', api.cells(api[i]).indexes().toArray() ], true );
1040
- } );
1048
+ this.iterator('table', function (ctx, i) {
1049
+ eventTrigger(api, 'select', ['cell', api.cells(api[i]).indexes().toArray()], true);
1050
+ });
1041
1051
 
1042
1052
  return this;
1043
- } );
1053
+ });
1044
1054
 
1045
- apiRegister( 'cell().selected()', function () {
1055
+ apiRegister('cell().selected()', function () {
1046
1056
  var ctx = this.context[0];
1047
1057
 
1048
1058
  if (ctx && this.length) {
@@ -1054,110 +1064,109 @@ apiRegister( 'cell().selected()', function () {
1054
1064
  }
1055
1065
 
1056
1066
  return false;
1057
- } );
1058
-
1067
+ });
1059
1068
 
1060
- apiRegisterPlural( 'rows().deselect()', 'row().deselect()', function () {
1069
+ apiRegisterPlural('rows().deselect()', 'row().deselect()', function () {
1061
1070
  var api = this;
1062
1071
 
1063
- this.iterator( 'row', function ( ctx, idx ) {
1064
- ctx.aoData[ idx ]._select_selected = false;
1072
+ this.iterator('row', function (ctx, idx) {
1073
+ ctx.aoData[idx]._select_selected = false;
1065
1074
  ctx._select_lastCell = null;
1066
- $( ctx.aoData[ idx ].nTr ).removeClass( ctx._select.className );
1067
- } );
1075
+ $(ctx.aoData[idx].nTr).removeClass(ctx._select.className);
1076
+ });
1068
1077
 
1069
- this.iterator( 'table', function ( ctx, i ) {
1070
- eventTrigger( api, 'deselect', [ 'row', api[i] ], true );
1071
- } );
1078
+ this.iterator('table', function (ctx, i) {
1079
+ eventTrigger(api, 'deselect', ['row', api[i]], true);
1080
+ });
1072
1081
 
1073
1082
  return this;
1074
- } );
1083
+ });
1075
1084
 
1076
- apiRegisterPlural( 'columns().deselect()', 'column().deselect()', function () {
1085
+ apiRegisterPlural('columns().deselect()', 'column().deselect()', function () {
1077
1086
  var api = this;
1078
1087
 
1079
- this.iterator( 'column', function ( ctx, idx ) {
1080
- ctx.aoColumns[ idx ]._select_selected = false;
1088
+ this.iterator('column', function (ctx, idx) {
1089
+ ctx.aoColumns[idx]._select_selected = false;
1081
1090
 
1082
- var api = new DataTable.Api( ctx );
1083
- var column = api.column( idx );
1091
+ var api = new DataTable.Api(ctx);
1092
+ var column = api.column(idx);
1084
1093
 
1085
- $( column.header() ).removeClass( ctx._select.className );
1086
- $( column.footer() ).removeClass( ctx._select.className );
1094
+ $(column.header()).removeClass(ctx._select.className);
1095
+ $(column.footer()).removeClass(ctx._select.className);
1087
1096
 
1088
1097
  // Need to loop over each cell, rather than just using
1089
1098
  // `column().nodes()` as cells which are individually selected should
1090
1099
  // not have the `selected` class removed from them
1091
- api.cells( null, idx ).indexes().each( function (cellIdx) {
1092
- var data = ctx.aoData[ cellIdx.row ];
1093
- var cellSelected = data._selected_cells;
1094
-
1095
- if ( data.anCells && (! cellSelected || ! cellSelected[ cellIdx.column ]) ) {
1096
- $( data.anCells[ cellIdx.column ] ).removeClass( ctx._select.className );
1097
- }
1098
- } );
1099
- } );
1100
+ api.cells(null, idx)
1101
+ .indexes()
1102
+ .each(function (cellIdx) {
1103
+ var data = ctx.aoData[cellIdx.row];
1104
+ var cellSelected = data._selected_cells;
1105
+
1106
+ if (data.anCells && (!cellSelected || !cellSelected[cellIdx.column])) {
1107
+ $(data.anCells[cellIdx.column]).removeClass(ctx._select.className);
1108
+ }
1109
+ });
1110
+ });
1100
1111
 
1101
- this.iterator( 'table', function ( ctx, i ) {
1102
- eventTrigger( api, 'deselect', [ 'column', api[i] ], true );
1103
- } );
1112
+ this.iterator('table', function (ctx, i) {
1113
+ eventTrigger(api, 'deselect', ['column', api[i]], true);
1114
+ });
1104
1115
 
1105
1116
  return this;
1106
- } );
1117
+ });
1107
1118
 
1108
- apiRegisterPlural( 'cells().deselect()', 'cell().deselect()', function () {
1119
+ apiRegisterPlural('cells().deselect()', 'cell().deselect()', function () {
1109
1120
  var api = this;
1110
1121
 
1111
- this.iterator( 'cell', function ( ctx, rowIdx, colIdx ) {
1112
- var data = ctx.aoData[ rowIdx ];
1122
+ this.iterator('cell', function (ctx, rowIdx, colIdx) {
1123
+ var data = ctx.aoData[rowIdx];
1113
1124
 
1114
- if(data._selected_cells !== undefined) {
1115
- data._selected_cells[ colIdx ] = false;
1125
+ if (data._selected_cells !== undefined) {
1126
+ data._selected_cells[colIdx] = false;
1116
1127
  }
1117
1128
 
1118
1129
  // Remove class only if the cells exist, and the cell is not column
1119
1130
  // selected, in which case the class should remain (since it is selected
1120
1131
  // in the column)
1121
- if ( data.anCells && ! ctx.aoColumns[ colIdx ]._select_selected ) {
1122
- $( data.anCells[ colIdx ] ).removeClass( ctx._select.className );
1132
+ if (data.anCells && !ctx.aoColumns[colIdx]._select_selected) {
1133
+ $(data.anCells[colIdx]).removeClass(ctx._select.className);
1123
1134
  }
1124
- } );
1135
+ });
1125
1136
 
1126
- this.iterator( 'table', function ( ctx, i ) {
1127
- eventTrigger( api, 'deselect', [ 'cell', api[i] ], true );
1128
- } );
1137
+ this.iterator('table', function (ctx, i) {
1138
+ eventTrigger(api, 'deselect', ['cell', api[i]], true);
1139
+ });
1129
1140
 
1130
1141
  return this;
1131
- } );
1132
-
1133
-
1142
+ });
1134
1143
 
1135
1144
  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1136
1145
  * Buttons
1137
1146
  */
1138
- function i18n( label, def ) {
1147
+ function i18n(label, def) {
1139
1148
  return function (dt) {
1140
- return dt.i18n( 'buttons.'+label, def );
1149
+ return dt.i18n('buttons.' + label, def);
1141
1150
  };
1142
1151
  }
1143
1152
 
1144
1153
  // Common events with suitable namespaces
1145
- function namespacedEvents ( config ) {
1154
+ function namespacedEvents(config) {
1146
1155
  var unique = config._eventNamespace;
1147
1156
 
1148
- return 'draw.dt.DT'+unique+' select.dt.DT'+unique+' deselect.dt.DT'+unique;
1157
+ return 'draw.dt.DT' + unique + ' select.dt.DT' + unique + ' deselect.dt.DT' + unique;
1149
1158
  }
1150
1159
 
1151
- function enabled ( dt, config ) {
1152
- if ( $.inArray( 'rows', config.limitTo ) !== -1 && dt.rows( { selected: true } ).any() ) {
1160
+ function enabled(dt, config) {
1161
+ if ($.inArray('rows', config.limitTo) !== -1 && dt.rows({ selected: true }).any()) {
1153
1162
  return true;
1154
1163
  }
1155
1164
 
1156
- if ( $.inArray( 'columns', config.limitTo ) !== -1 && dt.columns( { selected: true } ).any() ) {
1165
+ if ($.inArray('columns', config.limitTo) !== -1 && dt.columns({ selected: true }).any()) {
1157
1166
  return true;
1158
1167
  }
1159
1168
 
1160
- if ( $.inArray( 'cells', config.limitTo ) !== -1 && dt.cells( { selected: true } ).any() ) {
1169
+ if ($.inArray('cells', config.limitTo) !== -1 && dt.cells({ selected: true }).any()) {
1161
1170
  return true;
1162
1171
  }
1163
1172
 
@@ -1166,82 +1175,96 @@ function enabled ( dt, config ) {
1166
1175
 
1167
1176
  var _buttonNamespace = 0;
1168
1177
 
1169
- $.extend( DataTable.ext.buttons, {
1178
+ $.extend(DataTable.ext.buttons, {
1170
1179
  selected: {
1171
- text: i18n( 'selected', 'Selected' ),
1180
+ text: i18n('selected', 'Selected'),
1172
1181
  className: 'buttons-selected',
1173
- limitTo: [ 'rows', 'columns', 'cells' ],
1174
- init: function ( dt, node, config ) {
1182
+ limitTo: ['rows', 'columns', 'cells'],
1183
+ init: function (dt, node, config) {
1175
1184
  var that = this;
1176
- config._eventNamespace = '.select'+(_buttonNamespace++);
1185
+ config._eventNamespace = '.select' + _buttonNamespace++;
1177
1186
 
1178
1187
  // .DT namespace listeners are removed by DataTables automatically
1179
1188
  // on table destroy
1180
- dt.on( namespacedEvents(config), function () {
1181
- that.enable( enabled(dt, config) );
1182
- } );
1189
+ dt.on(namespacedEvents(config), function () {
1190
+ that.enable(enabled(dt, config));
1191
+ });
1183
1192
 
1184
1193
  this.disable();
1185
1194
  },
1186
- destroy: function ( dt, node, config ) {
1187
- dt.off( config._eventNamespace );
1195
+ destroy: function (dt, node, config) {
1196
+ dt.off(config._eventNamespace);
1188
1197
  }
1189
1198
  },
1190
1199
  selectedSingle: {
1191
- text: i18n( 'selectedSingle', 'Selected single' ),
1200
+ text: i18n('selectedSingle', 'Selected single'),
1192
1201
  className: 'buttons-selected-single',
1193
- init: function ( dt, node, config ) {
1202
+ init: function (dt, node, config) {
1194
1203
  var that = this;
1195
- config._eventNamespace = '.select'+(_buttonNamespace++);
1204
+ config._eventNamespace = '.select' + _buttonNamespace++;
1196
1205
 
1197
- dt.on( namespacedEvents(config), function () {
1198
- var count = dt.rows( { selected: true } ).flatten().length +
1199
- dt.columns( { selected: true } ).flatten().length +
1200
- dt.cells( { selected: true } ).flatten().length;
1206
+ dt.on(namespacedEvents(config), function () {
1207
+ var count =
1208
+ dt.rows({ selected: true }).flatten().length +
1209
+ dt.columns({ selected: true }).flatten().length +
1210
+ dt.cells({ selected: true }).flatten().length;
1201
1211
 
1202
- that.enable( count === 1 );
1203
- } );
1212
+ that.enable(count === 1);
1213
+ });
1204
1214
 
1205
1215
  this.disable();
1206
1216
  },
1207
- destroy: function ( dt, node, config ) {
1208
- dt.off( config._eventNamespace );
1217
+ destroy: function (dt, node, config) {
1218
+ dt.off(config._eventNamespace);
1209
1219
  }
1210
1220
  },
1211
1221
  selectAll: {
1212
- text: i18n( 'selectAll', 'Select all' ),
1222
+ text: i18n('selectAll', 'Select all'),
1213
1223
  className: 'buttons-select-all',
1214
- action: function () {
1224
+ action: function (e, dt, node, config) {
1215
1225
  var items = this.select.items();
1216
- this[ items+'s' ]().select();
1226
+ var mod = config.selectorModifier;
1227
+
1228
+ if (mod) {
1229
+ if (typeof mod === 'function') {
1230
+ mod = mod.call(dt, e, dt, node, config);
1231
+ }
1232
+
1233
+ this[items + 's'](mod).select();
1234
+ }
1235
+ else {
1236
+ this[items + 's']().select();
1237
+ }
1217
1238
  }
1239
+ // selectorModifier can be specified
1218
1240
  },
1219
1241
  selectNone: {
1220
- text: i18n( 'selectNone', 'Deselect all' ),
1242
+ text: i18n('selectNone', 'Deselect all'),
1221
1243
  className: 'buttons-select-none',
1222
1244
  action: function () {
1223
- clear( this.settings()[0], true );
1245
+ clear(this.settings()[0], true);
1224
1246
  },
1225
- init: function ( dt, node, config ) {
1247
+ init: function (dt, node, config) {
1226
1248
  var that = this;
1227
- config._eventNamespace = '.select'+(_buttonNamespace++);
1249
+ config._eventNamespace = '.select' + _buttonNamespace++;
1228
1250
 
1229
- dt.on( namespacedEvents(config), function () {
1230
- var count = dt.rows( { selected: true } ).flatten().length +
1231
- dt.columns( { selected: true } ).flatten().length +
1232
- dt.cells( { selected: true } ).flatten().length;
1251
+ dt.on(namespacedEvents(config), function () {
1252
+ var count =
1253
+ dt.rows({ selected: true }).flatten().length +
1254
+ dt.columns({ selected: true }).flatten().length +
1255
+ dt.cells({ selected: true }).flatten().length;
1233
1256
 
1234
- that.enable( count > 0 );
1235
- } );
1257
+ that.enable(count > 0);
1258
+ });
1236
1259
 
1237
1260
  this.disable();
1238
1261
  },
1239
- destroy: function ( dt, node, config ) {
1240
- dt.off( config._eventNamespace );
1262
+ destroy: function (dt, node, config) {
1263
+ dt.off(config._eventNamespace);
1241
1264
  }
1242
1265
  },
1243
1266
  showSelected: {
1244
- text: i18n( 'showSelected', 'Show only selected' ),
1267
+ text: i18n('showSelected', 'Show only selected'),
1245
1268
  className: 'buttons-show-selected',
1246
1269
  action: function (e, dt, node, conf) {
1247
1270
  // Works by having a filtering function which will reduce to the selected
@@ -1267,7 +1290,7 @@ $.extend( DataTable.ext.buttons, {
1267
1290
  let row = s.aoData[idx];
1268
1291
 
1269
1292
  return row._select_selected;
1270
- }
1293
+ };
1271
1294
 
1272
1295
  conf._filter = fn;
1273
1296
  DataTable.ext.search.push(fn);
@@ -1278,27 +1301,26 @@ $.extend( DataTable.ext.buttons, {
1278
1301
  dt.draw();
1279
1302
  }
1280
1303
  }
1281
- } );
1304
+ });
1282
1305
 
1283
- $.each( [ 'Row', 'Column', 'Cell' ], function ( i, item ) {
1306
+ $.each(['Row', 'Column', 'Cell'], function (i, item) {
1284
1307
  var lc = item.toLowerCase();
1285
1308
 
1286
- DataTable.ext.buttons[ 'select'+item+'s' ] = {
1287
- text: i18n( 'select'+item+'s', 'Select '+lc+'s' ),
1288
- className: 'buttons-select-'+lc+'s',
1309
+ DataTable.ext.buttons['select' + item + 's'] = {
1310
+ text: i18n('select' + item + 's', 'Select ' + lc + 's'),
1311
+ className: 'buttons-select-' + lc + 's',
1289
1312
  action: function () {
1290
- this.select.items( lc );
1313
+ this.select.items(lc);
1291
1314
  },
1292
- init: function ( dt ) {
1315
+ init: function (dt) {
1293
1316
  var that = this;
1294
1317
 
1295
- dt.on( 'selectItems.dt.DT', function ( e, ctx, items ) {
1296
- that.active( items === lc );
1297
- } );
1318
+ dt.on('selectItems.dt.DT', function (e, ctx, items) {
1319
+ that.active(items === lc);
1320
+ });
1298
1321
  }
1299
1322
  };
1300
- } );
1301
-
1323
+ });
1302
1324
 
1303
1325
  $.fn.DataTable.select = DataTable.select;
1304
1326
 
@@ -1310,13 +1332,13 @@ $.fn.DataTable.select = DataTable.select;
1310
1332
  // this required that the table be in the document! If it isn't then something
1311
1333
  // needs to trigger this method unfortunately. The next major release of
1312
1334
  // DataTables will rework the events and address this.
1313
- $(document).on( 'preInit.dt.dtSelect', function (e, ctx) {
1314
- if ( e.namespace !== 'dt' ) {
1335
+ $(document).on('preInit.dt.dtSelect', function (e, ctx) {
1336
+ if (e.namespace !== 'dt') {
1315
1337
  return;
1316
1338
  }
1317
1339
 
1318
- DataTable.select.init( new DataTable.Api( ctx ) );
1319
- } );
1340
+ DataTable.select.init(new DataTable.Api(ctx));
1341
+ });
1320
1342
 
1321
1343
 
1322
1344
  export default DataTable;