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