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