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