datatables.net-columncontrol 1.0.7 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! ColumnControl 1.
|
|
1
|
+
/*! ColumnControl 1.1.1
|
|
2
2
|
* Copyright (c) SpryMedia Ltd - datatables.net/license
|
|
3
3
|
*
|
|
4
4
|
* SVG icons: ISC License
|
|
@@ -102,6 +102,14 @@ var icons = {
|
|
|
102
102
|
greater: wrap('<path d="m9 18 6-6-6-6"/>'),
|
|
103
103
|
// Custom
|
|
104
104
|
greaterOrEqual: wrap('<path d="m9 16 6-6-6-6"/><path d="m9 21 6-6"/>'),
|
|
105
|
+
// Custom
|
|
106
|
+
groupAdd: wrap('<path d="M6 21v-7.5m-3.549 3.75H9.75"/><rect width="13.5" height="7.5" x="3" y="3" rx="1.5"/><rect width="7.5" height="7.5" x="13.5" y="13.5" fill="currentColor" rx="1.5"/>'),
|
|
107
|
+
// Custom
|
|
108
|
+
groupClear: wrap('<rect width="13.5" height="7.5" x="3" y="3" rx="1.5"/><rect width="7.5" height="7.5" x="13.5" y="13.5" rx="1.5"/>'),
|
|
109
|
+
// Custom
|
|
110
|
+
groupTop: wrap('<rect width="13.5" height="7.5" x="3" y="3" fill="currentColor" rx="1.5"/><rect width="7.5" height="7.5" x="13.5" y="13.5" rx="1.5"/>'),
|
|
111
|
+
// Custom
|
|
112
|
+
groupRemove: wrap('<path d="M2.451 17.25H9.75"/><rect width="13.5" height="7.5" x="3" y="3" rx="1.5"/><rect width="7.5" height="7.5" x="13.5" y="13.5" rx="1.5"/>'),
|
|
105
113
|
less: wrap('<path d="m15 18-6-6 6-6"/>'),
|
|
106
114
|
// Custom
|
|
107
115
|
lessOrEqual: wrap('<path d="m15 16-6-6 6-6"/><path d="m15 21-6-6"/>'),
|
|
@@ -208,6 +216,7 @@ function attachDropdown(dropdown, dt, btn) {
|
|
|
208
216
|
dropdown._shown = true;
|
|
209
217
|
dtContainer.append(dropdown);
|
|
210
218
|
positionDropdown(dropdown, dt, btn.element());
|
|
219
|
+
btn.element().setAttribute('aria-expanded', 'true');
|
|
211
220
|
// Note that this could be called when the dropdown has already been removed from the document
|
|
212
221
|
// via another dropdown being shown. This will clean up the event on the next body click.
|
|
213
222
|
var removeDropdown = function (e) {
|
|
@@ -220,6 +229,12 @@ function attachDropdown(dropdown, dt, btn) {
|
|
|
220
229
|
if (e.target === dropdown || dropdown.contains(e.target)) {
|
|
221
230
|
return;
|
|
222
231
|
}
|
|
232
|
+
// If there is currently a datetime picker visible on the page, assume that it belongs to
|
|
233
|
+
// this dropdown. Don't want to close while operating on the picker.
|
|
234
|
+
var datetime = document.querySelector('div.dt-datetime');
|
|
235
|
+
if (datetime && (e.target === datetime || datetime.contains(e.target))) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
223
238
|
dropdown._close();
|
|
224
239
|
document.body.removeEventListener('click', removeDropdown);
|
|
225
240
|
};
|
|
@@ -317,6 +332,7 @@ var dropdownContent = {
|
|
|
317
332
|
dropdown._close = function () {
|
|
318
333
|
dropdown.remove();
|
|
319
334
|
dropdown._shown = false;
|
|
335
|
+
btn.element().setAttribute('aria-expanded', 'false');
|
|
320
336
|
};
|
|
321
337
|
dropdown.setAttribute('role', 'dialog');
|
|
322
338
|
dropdown.setAttribute('aria-label', dt.i18n('columnControl.dropdown', config.text));
|
|
@@ -329,7 +345,7 @@ var dropdownContent = {
|
|
|
329
345
|
});
|
|
330
346
|
// A liner element allows more styling options, so the contents go inside this
|
|
331
347
|
var liner = dropdown.childNodes[0];
|
|
332
|
-
var btn = new Button(dt)
|
|
348
|
+
var btn = new Button(dt, this)
|
|
333
349
|
.text(dt.i18n('columnControl.dropdown', config.text))
|
|
334
350
|
.icon(config.icon)
|
|
335
351
|
.className(config.className)
|
|
@@ -348,6 +364,7 @@ var dropdownContent = {
|
|
|
348
364
|
}
|
|
349
365
|
});
|
|
350
366
|
btn.element().setAttribute('aria-haspopup', 'dialog');
|
|
367
|
+
btn.element().setAttribute('aria-expanded', 'false');
|
|
351
368
|
// Add the content for the dropdown
|
|
352
369
|
for (var i = 0; i < config.content.length; i++) {
|
|
353
370
|
var content = this.resolve(config.content[i]);
|
|
@@ -384,18 +401,20 @@ var Button = /** @class */ (function () {
|
|
|
384
401
|
* Create a new button for use in ColumnControl contents. Buttons created by this class can be
|
|
385
402
|
* used at the top level in the header or in a dropdown.
|
|
386
403
|
*/
|
|
387
|
-
function Button(dt) {
|
|
404
|
+
function Button(dt, host) {
|
|
388
405
|
this._s = {
|
|
389
406
|
active: false,
|
|
390
407
|
activeList: [],
|
|
391
408
|
buttonClick: null,
|
|
392
409
|
dt: null,
|
|
393
410
|
enabled: true,
|
|
411
|
+
host: null,
|
|
394
412
|
label: '',
|
|
395
413
|
namespace: '',
|
|
396
414
|
value: null
|
|
397
415
|
};
|
|
398
416
|
this._s.dt = dt;
|
|
417
|
+
this._s.host = host;
|
|
399
418
|
this._dom = {
|
|
400
419
|
button: createElement('button', Button.classes.container),
|
|
401
420
|
dropdownDisplay: null,
|
|
@@ -473,9 +492,7 @@ var Button = /** @class */ (function () {
|
|
|
473
492
|
this._dom.button.removeEventListener('click', this._s.buttonClick);
|
|
474
493
|
this._dom.button.removeEventListener('keypress', this._s.buttonClick);
|
|
475
494
|
}
|
|
476
|
-
|
|
477
|
-
this._s.dt.off('destroy.' + this._s.namespace);
|
|
478
|
-
}
|
|
495
|
+
this._s.host.destroyRemove(this);
|
|
479
496
|
};
|
|
480
497
|
/**
|
|
481
498
|
* Relevant for drop downs only. When a button in a dropdown is hidden, we might want to
|
|
@@ -497,13 +514,10 @@ var Button = /** @class */ (function () {
|
|
|
497
514
|
Button.prototype.element = function () {
|
|
498
515
|
return this._dom.button;
|
|
499
516
|
};
|
|
500
|
-
/**
|
|
501
|
-
* Set if the button should be enabled or not.
|
|
502
|
-
*
|
|
503
|
-
* @param enable Toggle the enable state
|
|
504
|
-
* @returns Button instance
|
|
505
|
-
*/
|
|
506
517
|
Button.prototype.enable = function (enable) {
|
|
518
|
+
if (enable === undefined) {
|
|
519
|
+
return this._s.enabled;
|
|
520
|
+
}
|
|
507
521
|
this._dom.button.classList.toggle('dtcc-button_disabled', !enable);
|
|
508
522
|
this._s.enabled = enable;
|
|
509
523
|
return this;
|
|
@@ -540,10 +554,7 @@ var Button = /** @class */ (function () {
|
|
|
540
554
|
this._s.namespace = 'dtcc-' + _namespace++;
|
|
541
555
|
this._dom.button.addEventListener('click', buttonClick);
|
|
542
556
|
this._dom.button.addEventListener('keypress', buttonClick);
|
|
543
|
-
|
|
544
|
-
this._s.dt.on('destroy.' + this._s.namespace, function () {
|
|
545
|
-
_this.destroy();
|
|
546
|
-
});
|
|
557
|
+
this._s.host.destroyAdd(this);
|
|
547
558
|
return this;
|
|
548
559
|
};
|
|
549
560
|
/**
|
|
@@ -598,19 +609,22 @@ var CheckList = /** @class */ (function () {
|
|
|
598
609
|
/**
|
|
599
610
|
* Container for a list of buttons
|
|
600
611
|
*/
|
|
601
|
-
function CheckList(dt, opts) {
|
|
612
|
+
function CheckList(dt, host, opts) {
|
|
602
613
|
var _this = this;
|
|
603
614
|
this._s = {
|
|
604
615
|
buttons: [],
|
|
605
616
|
dt: null,
|
|
606
617
|
handler: function () { },
|
|
618
|
+
host: null,
|
|
607
619
|
search: ''
|
|
608
620
|
};
|
|
609
621
|
this._s.dt = dt;
|
|
622
|
+
this._s.host = host;
|
|
610
623
|
this._dom = {
|
|
611
624
|
buttons: createElement('div', 'dtcc-list-buttons'),
|
|
612
625
|
container: createElement('div', CheckList.classes.container),
|
|
613
626
|
controls: createElement('div', 'dtcc-list-controls'),
|
|
627
|
+
empty: createElement('div', 'dtcc-list-empty', dt.i18n('columnControl.list.empty', 'No options')),
|
|
614
628
|
title: createElement('div', 'dtcc-list-title'),
|
|
615
629
|
selectAll: createElement('button', 'dtcc-list-selectAll', dt.i18n('columnControl.list.all', 'Select all')),
|
|
616
630
|
selectAllCount: createElement('span'),
|
|
@@ -622,6 +636,7 @@ var CheckList = /** @class */ (function () {
|
|
|
622
636
|
dom.search.setAttribute('type', 'text');
|
|
623
637
|
dom.container.append(dom.title);
|
|
624
638
|
dom.container.append(dom.controls);
|
|
639
|
+
dom.container.append(dom.empty);
|
|
625
640
|
dom.container.append(dom.buttons);
|
|
626
641
|
if (opts.select) {
|
|
627
642
|
dom.controls.append(dom.selectAll);
|
|
@@ -672,7 +687,7 @@ var CheckList = /** @class */ (function () {
|
|
|
672
687
|
}
|
|
673
688
|
var _loop_1 = function (i) {
|
|
674
689
|
var option = options[i];
|
|
675
|
-
var btn = new Button(this_1._s.dt)
|
|
690
|
+
var btn = new Button(this_1._s.dt, this_1._s.host)
|
|
676
691
|
.active(option.active || false)
|
|
677
692
|
.handler(function (e) {
|
|
678
693
|
_this._s.handler(e, btn, _this._s.buttons, true);
|
|
@@ -681,7 +696,7 @@ var CheckList = /** @class */ (function () {
|
|
|
681
696
|
.icon(option.icon || '')
|
|
682
697
|
.text(option.label !== ''
|
|
683
698
|
? option.label
|
|
684
|
-
: this_1._s.dt.i18n('columnControl.list.
|
|
699
|
+
: this_1._s.dt.i18n('columnControl.list.empty', 'Empty'))
|
|
685
700
|
.value(option.value);
|
|
686
701
|
if (option.label === '') {
|
|
687
702
|
btn.className('empty');
|
|
@@ -752,11 +767,11 @@ var CheckList = /** @class */ (function () {
|
|
|
752
767
|
* @param dt DataTable instance
|
|
753
768
|
* @param idx Column index
|
|
754
769
|
*/
|
|
755
|
-
CheckList.prototype.searchListener = function (dt
|
|
770
|
+
CheckList.prototype.searchListener = function (dt) {
|
|
756
771
|
var _this = this;
|
|
757
|
-
// Column control search clearing (column().
|
|
772
|
+
// Column control search clearing (column().columnControl.searchClear() method)
|
|
758
773
|
dt.on('cc-search-clear', function (e, colIdx) {
|
|
759
|
-
if (colIdx ===
|
|
774
|
+
if (colIdx === _this._s.host.idx()) {
|
|
760
775
|
_this.selectNone();
|
|
761
776
|
_this._s.handler(e, null, _this._s.buttons, false);
|
|
762
777
|
_this._s.search = '';
|
|
@@ -844,6 +859,8 @@ var CheckList = /** @class */ (function () {
|
|
|
844
859
|
el.appendChild(btn.element());
|
|
845
860
|
}
|
|
846
861
|
}
|
|
862
|
+
this._dom.empty.style.display = buttons.length === 0 ? 'block' : 'none';
|
|
863
|
+
el.style.display = buttons.length > 0 ? 'block' : 'none';
|
|
847
864
|
};
|
|
848
865
|
CheckList.classes = {
|
|
849
866
|
container: 'dtcc-list',
|
|
@@ -862,7 +879,7 @@ var colVis = {
|
|
|
862
879
|
},
|
|
863
880
|
init: function (config) {
|
|
864
881
|
var dt = this.dt();
|
|
865
|
-
var checkList = new CheckList(dt, {
|
|
882
|
+
var checkList = new CheckList(dt, this, {
|
|
866
883
|
search: config.search,
|
|
867
884
|
select: config.select
|
|
868
885
|
})
|
|
@@ -945,16 +962,12 @@ var reorder = {
|
|
|
945
962
|
init: function (config) {
|
|
946
963
|
var _this = this;
|
|
947
964
|
var dt = this.dt();
|
|
948
|
-
var btn = new Button(dt)
|
|
965
|
+
var btn = new Button(dt, this)
|
|
949
966
|
.text(dt.i18n('columnControl.reorder', config.text))
|
|
950
967
|
.icon(config.icon)
|
|
951
|
-
.className(config.className)
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
if (idx > 0) {
|
|
955
|
-
dt.colReorder.move(idx, idx - 1);
|
|
956
|
-
}
|
|
957
|
-
});
|
|
968
|
+
.className(config.className);
|
|
969
|
+
// The event handling for this is done in ColReorder._addListener - no event
|
|
970
|
+
// handler needed here for click / drag
|
|
958
971
|
if (this.idx() === 0) {
|
|
959
972
|
btn.enable(false);
|
|
960
973
|
}
|
|
@@ -978,7 +991,7 @@ var reorderLeft = {
|
|
|
978
991
|
init: function (config) {
|
|
979
992
|
var _this = this;
|
|
980
993
|
var dt = this.dt();
|
|
981
|
-
var btn = new Button(dt)
|
|
994
|
+
var btn = new Button(dt, this)
|
|
982
995
|
.text(dt.i18n('columnControl.reorderLeft', config.text))
|
|
983
996
|
.icon(config.icon)
|
|
984
997
|
.className(config.className)
|
|
@@ -1008,7 +1021,7 @@ var reorderRight = {
|
|
|
1008
1021
|
init: function (config) {
|
|
1009
1022
|
var _this = this;
|
|
1010
1023
|
var dt = this.dt();
|
|
1011
|
-
var btn = new Button(dt)
|
|
1024
|
+
var btn = new Button(dt, this)
|
|
1012
1025
|
.text(dt.i18n('columnControl.reorderRight', config.text))
|
|
1013
1026
|
.icon(config.icon)
|
|
1014
1027
|
.className(config.className)
|
|
@@ -1040,7 +1053,7 @@ var order = {
|
|
|
1040
1053
|
init: function (config) {
|
|
1041
1054
|
var _this = this;
|
|
1042
1055
|
var dt = this.dt();
|
|
1043
|
-
var btn = new Button(dt)
|
|
1056
|
+
var btn = new Button(dt, this)
|
|
1044
1057
|
.text(dt.i18n('columnControl.order', config.text))
|
|
1045
1058
|
.icon('orderAsc')
|
|
1046
1059
|
.className(config.className);
|
|
@@ -1072,7 +1085,7 @@ var orderAddAsc = {
|
|
|
1072
1085
|
init: function (config) {
|
|
1073
1086
|
var _this = this;
|
|
1074
1087
|
var dt = this.dt();
|
|
1075
|
-
var btn = new Button(dt)
|
|
1088
|
+
var btn = new Button(dt, this)
|
|
1076
1089
|
.text(dt.i18n('columnControl.orderAddAsc', config.text))
|
|
1077
1090
|
.icon(config.icon)
|
|
1078
1091
|
.className(config.className)
|
|
@@ -1098,7 +1111,7 @@ var orderAddDesc = {
|
|
|
1098
1111
|
init: function (config) {
|
|
1099
1112
|
var _this = this;
|
|
1100
1113
|
var dt = this.dt();
|
|
1101
|
-
var btn = new Button(dt)
|
|
1114
|
+
var btn = new Button(dt, this)
|
|
1102
1115
|
.text(dt.i18n('columnControl.orderAddDesc', config.text))
|
|
1103
1116
|
.icon(config.icon)
|
|
1104
1117
|
.className(config.className)
|
|
@@ -1124,7 +1137,7 @@ var orderAsc = {
|
|
|
1124
1137
|
init: function (config) {
|
|
1125
1138
|
var _this = this;
|
|
1126
1139
|
var dt = this.dt();
|
|
1127
|
-
var btn = new Button(dt)
|
|
1140
|
+
var btn = new Button(dt, this)
|
|
1128
1141
|
.text(dt.i18n('columnControl.orderAsc', config.text))
|
|
1129
1142
|
.icon(config.icon)
|
|
1130
1143
|
.className(config.className)
|
|
@@ -1154,7 +1167,7 @@ var orderClear = {
|
|
|
1154
1167
|
},
|
|
1155
1168
|
init: function (config) {
|
|
1156
1169
|
var dt = this.dt();
|
|
1157
|
-
var btn = new Button(dt)
|
|
1170
|
+
var btn = new Button(dt, this)
|
|
1158
1171
|
.text(dt.i18n('columnControl.orderClear', config.text))
|
|
1159
1172
|
.icon(config.icon)
|
|
1160
1173
|
.className(config.className)
|
|
@@ -1180,7 +1193,7 @@ var orderDesc = {
|
|
|
1180
1193
|
init: function (config) {
|
|
1181
1194
|
var _this = this;
|
|
1182
1195
|
var dt = this.dt();
|
|
1183
|
-
var btn = new Button(dt)
|
|
1196
|
+
var btn = new Button(dt, this)
|
|
1184
1197
|
.text(dt.i18n('columnControl.orderDesc', config.text))
|
|
1185
1198
|
.icon(config.icon)
|
|
1186
1199
|
.className(config.className)
|
|
@@ -1211,7 +1224,7 @@ var orderRemove = {
|
|
|
1211
1224
|
init: function (config) {
|
|
1212
1225
|
var _this = this;
|
|
1213
1226
|
var dt = this.dt();
|
|
1214
|
-
var btn = new Button(dt)
|
|
1227
|
+
var btn = new Button(dt, this)
|
|
1215
1228
|
.text(dt.i18n('columnControl.orderRemove', config.text))
|
|
1216
1229
|
.icon(config.icon)
|
|
1217
1230
|
.className(config.className)
|
|
@@ -1245,6 +1258,190 @@ var orderStatus = {
|
|
|
1245
1258
|
}
|
|
1246
1259
|
};
|
|
1247
1260
|
|
|
1261
|
+
/**
|
|
1262
|
+
* Add an item to the grouping structure
|
|
1263
|
+
*
|
|
1264
|
+
* @param dt DataTable API instance
|
|
1265
|
+
* @param dataSrc Grouping data point to add
|
|
1266
|
+
* @returns Grouping array
|
|
1267
|
+
*/
|
|
1268
|
+
function rowGroupAdd$1(dt, dataSrc) {
|
|
1269
|
+
var applied = rowGroupApplied(dt);
|
|
1270
|
+
var idx = applied.indexOf(dataSrc);
|
|
1271
|
+
if (idx === -1) {
|
|
1272
|
+
applied.push(dataSrc);
|
|
1273
|
+
dt.rowGroup().dataSrc(applied);
|
|
1274
|
+
}
|
|
1275
|
+
return applied;
|
|
1276
|
+
}
|
|
1277
|
+
/**
|
|
1278
|
+
* Always want an array return
|
|
1279
|
+
*
|
|
1280
|
+
* @param dt DataTable API instance
|
|
1281
|
+
* @returns
|
|
1282
|
+
*/
|
|
1283
|
+
function rowGroupApplied(dt) {
|
|
1284
|
+
var applied = dt.rowGroup().dataSrc();
|
|
1285
|
+
return Array.isArray(applied)
|
|
1286
|
+
? applied
|
|
1287
|
+
: [applied];
|
|
1288
|
+
}
|
|
1289
|
+
/**
|
|
1290
|
+
* Remove all grouping
|
|
1291
|
+
*
|
|
1292
|
+
* @param dt DataTable API instance
|
|
1293
|
+
*/
|
|
1294
|
+
function rowGroupClear$1(dt) {
|
|
1295
|
+
dt.rowGroup().dataSrc([]);
|
|
1296
|
+
}
|
|
1297
|
+
/**
|
|
1298
|
+
* Remove an item from the grouping structure
|
|
1299
|
+
*
|
|
1300
|
+
* @param dt DataTable API instance
|
|
1301
|
+
* @param dataSrc Grouping data point to remove
|
|
1302
|
+
* @returns Grouping array
|
|
1303
|
+
*/
|
|
1304
|
+
function rowGroupRemove$1(dt, dataSrc) {
|
|
1305
|
+
var applied = rowGroupApplied(dt);
|
|
1306
|
+
var idx = applied.indexOf(dataSrc);
|
|
1307
|
+
if (idx !== -1) {
|
|
1308
|
+
applied.splice(idx, 1);
|
|
1309
|
+
dt.rowGroup().dataSrc(applied);
|
|
1310
|
+
}
|
|
1311
|
+
return applied;
|
|
1312
|
+
}
|
|
1313
|
+
var rowGroup = {
|
|
1314
|
+
defaults: {
|
|
1315
|
+
className: 'rowGroup',
|
|
1316
|
+
icon: 'groupTop',
|
|
1317
|
+
order: true,
|
|
1318
|
+
text: 'Group rows'
|
|
1319
|
+
},
|
|
1320
|
+
init: function (config) {
|
|
1321
|
+
var _this = this;
|
|
1322
|
+
var dt = this.dt();
|
|
1323
|
+
var btn = new Button(dt, this)
|
|
1324
|
+
.text(dt.i18n('columnControl.rowGroup', config.text))
|
|
1325
|
+
.icon(config.icon)
|
|
1326
|
+
.className(config.className)
|
|
1327
|
+
.handler(function () {
|
|
1328
|
+
var dataSrc = dt.column(_this.idx()).dataSrc();
|
|
1329
|
+
if (btn.active()) {
|
|
1330
|
+
// Grouping is active - remove
|
|
1331
|
+
rowGroupRemove$1(dt, dataSrc);
|
|
1332
|
+
}
|
|
1333
|
+
else {
|
|
1334
|
+
// No grouping by this column yet, set it
|
|
1335
|
+
rowGroupClear$1(dt);
|
|
1336
|
+
rowGroupAdd$1(dt, dataSrc);
|
|
1337
|
+
if (config.order !== false) {
|
|
1338
|
+
dt.order([_this.idx(), 'asc']);
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
dt.draw();
|
|
1342
|
+
});
|
|
1343
|
+
// Show as active when grouping is applied
|
|
1344
|
+
dt.on('rowgroup-datasrc', function () {
|
|
1345
|
+
var applied = rowGroupApplied(dt);
|
|
1346
|
+
var ours = dt.column(_this.idx()).dataSrc();
|
|
1347
|
+
btn.active(applied.includes(ours));
|
|
1348
|
+
});
|
|
1349
|
+
return btn.element();
|
|
1350
|
+
}
|
|
1351
|
+
};
|
|
1352
|
+
|
|
1353
|
+
var rowGroupAdd = {
|
|
1354
|
+
defaults: {
|
|
1355
|
+
className: 'rowGroupAdd',
|
|
1356
|
+
icon: 'groupAdd',
|
|
1357
|
+
order: true,
|
|
1358
|
+
text: 'Add to grouping'
|
|
1359
|
+
},
|
|
1360
|
+
init: function (config) {
|
|
1361
|
+
var _this = this;
|
|
1362
|
+
var dt = this.dt();
|
|
1363
|
+
var btn = new Button(dt, this)
|
|
1364
|
+
.text(dt.i18n('columnControl.rowGroup', config.text))
|
|
1365
|
+
.icon(config.icon)
|
|
1366
|
+
.className(config.className)
|
|
1367
|
+
.handler(function () {
|
|
1368
|
+
var dataSrc = dt.column(_this.idx()).dataSrc();
|
|
1369
|
+
if (btn.enable()) {
|
|
1370
|
+
// No grouping by this column yet, add it
|
|
1371
|
+
rowGroupAdd$1(dt, dataSrc);
|
|
1372
|
+
}
|
|
1373
|
+
dt.draw();
|
|
1374
|
+
});
|
|
1375
|
+
// Show as active when grouping is applied
|
|
1376
|
+
dt.on('rowgroup-datasrc', function () {
|
|
1377
|
+
var applied = rowGroupApplied(dt);
|
|
1378
|
+
var ours = dt.column(_this.idx()).dataSrc();
|
|
1379
|
+
btn.enable(!applied.includes(ours));
|
|
1380
|
+
});
|
|
1381
|
+
return btn.element();
|
|
1382
|
+
}
|
|
1383
|
+
};
|
|
1384
|
+
|
|
1385
|
+
var rowGroupClear = {
|
|
1386
|
+
defaults: {
|
|
1387
|
+
className: 'rowGroupClear',
|
|
1388
|
+
icon: 'groupClear',
|
|
1389
|
+
text: 'Clear all grouping'
|
|
1390
|
+
},
|
|
1391
|
+
init: function (config) {
|
|
1392
|
+
var dt = this.dt();
|
|
1393
|
+
var btn = new Button(dt, this)
|
|
1394
|
+
.text(dt.i18n('columnControl.rowGroup', config.text))
|
|
1395
|
+
.icon(config.icon)
|
|
1396
|
+
.className(config.className)
|
|
1397
|
+
.handler(function () {
|
|
1398
|
+
rowGroupClear$1(dt);
|
|
1399
|
+
dt.draw();
|
|
1400
|
+
});
|
|
1401
|
+
// Show as active when any grouping is applied
|
|
1402
|
+
dt.on('rowgroup-datasrc', function () {
|
|
1403
|
+
btn.enable(rowGroupApplied(dt).length > 0);
|
|
1404
|
+
});
|
|
1405
|
+
// Default status
|
|
1406
|
+
btn.enable(rowGroupApplied(dt).length > 0);
|
|
1407
|
+
return btn.element();
|
|
1408
|
+
}
|
|
1409
|
+
};
|
|
1410
|
+
|
|
1411
|
+
var rowGroupRemove = {
|
|
1412
|
+
defaults: {
|
|
1413
|
+
className: 'rowGroupRemove',
|
|
1414
|
+
icon: 'groupRemove',
|
|
1415
|
+
order: true,
|
|
1416
|
+
text: 'Remove from grouping'
|
|
1417
|
+
},
|
|
1418
|
+
init: function (config) {
|
|
1419
|
+
var _this = this;
|
|
1420
|
+
var dt = this.dt();
|
|
1421
|
+
var btn = new Button(dt, this)
|
|
1422
|
+
.text(dt.i18n('columnControl.rowGroup', config.text))
|
|
1423
|
+
.icon(config.icon)
|
|
1424
|
+
.className(config.className)
|
|
1425
|
+
.handler(function () {
|
|
1426
|
+
var dataSrc = dt.column(_this.idx()).dataSrc();
|
|
1427
|
+
if (btn.enable()) {
|
|
1428
|
+
// Grouping is active - remove
|
|
1429
|
+
rowGroupRemove$1(dt, dataSrc);
|
|
1430
|
+
dt.draw();
|
|
1431
|
+
}
|
|
1432
|
+
});
|
|
1433
|
+
// Show as active when grouping is applied
|
|
1434
|
+
dt.on('rowgroup-datasrc', function () {
|
|
1435
|
+
var applied = rowGroupApplied(dt);
|
|
1436
|
+
var ours = dt.column(_this.idx()).dataSrc();
|
|
1437
|
+
btn.enable(applied.includes(ours));
|
|
1438
|
+
});
|
|
1439
|
+
// Default disabled
|
|
1440
|
+
btn.enable(false);
|
|
1441
|
+
return btn.element();
|
|
1442
|
+
}
|
|
1443
|
+
};
|
|
1444
|
+
|
|
1248
1445
|
var SearchInput = /** @class */ (function () {
|
|
1249
1446
|
/**
|
|
1250
1447
|
* Create a container element, for consistent DOM structure and styling
|
|
@@ -1252,6 +1449,8 @@ var SearchInput = /** @class */ (function () {
|
|
|
1252
1449
|
function SearchInput(dt, idx) {
|
|
1253
1450
|
var _this = this;
|
|
1254
1451
|
this._type = 'text';
|
|
1452
|
+
this._sspTransform = null;
|
|
1453
|
+
this._sspData = {};
|
|
1255
1454
|
this._dt = dt;
|
|
1256
1455
|
this._idx = idx;
|
|
1257
1456
|
this._dom = {
|
|
@@ -1290,28 +1489,28 @@ var SearchInput = /** @class */ (function () {
|
|
|
1290
1489
|
});
|
|
1291
1490
|
// State handling - all components that use this class have the same state saving structure
|
|
1292
1491
|
// so shared handling can be performed here.
|
|
1293
|
-
dt.on('stateSaveParams', function (e, s, data) {
|
|
1492
|
+
dt.on('stateSaveParams.DT', function (e, s, data) {
|
|
1294
1493
|
if (!data.columnControl) {
|
|
1295
1494
|
data.columnControl = {};
|
|
1296
1495
|
}
|
|
1297
|
-
if (!data.columnControl[
|
|
1298
|
-
data.columnControl[
|
|
1496
|
+
if (!data.columnControl[_this._idx]) {
|
|
1497
|
+
data.columnControl[_this._idx] = {};
|
|
1299
1498
|
}
|
|
1300
|
-
data.columnControl[
|
|
1499
|
+
data.columnControl[_this._idx].searchInput = {
|
|
1301
1500
|
logic: dom.select.value,
|
|
1302
1501
|
type: _this._type,
|
|
1303
1502
|
value: dom.input.value
|
|
1304
1503
|
};
|
|
1305
1504
|
});
|
|
1306
|
-
dt.on('stateLoaded', function (e, s, state) {
|
|
1505
|
+
dt.on('stateLoaded.DT', function (e, s, state) {
|
|
1307
1506
|
_this._stateLoad(state);
|
|
1308
1507
|
});
|
|
1309
1508
|
// Same as for ColumnControl - reassign a column index if needed.
|
|
1310
|
-
dt.on('columns-reordered', function (e, details) {
|
|
1509
|
+
dt.on('columns-reordered.DT', function (e, details) {
|
|
1311
1510
|
_this._idx = dt.colReorder.transpose(originalIdx, 'fromOriginal');
|
|
1312
1511
|
});
|
|
1313
|
-
// Column control search clearing (column().
|
|
1314
|
-
dt.on('cc-search-clear', function (e, colIdx) {
|
|
1512
|
+
// Column control search clearing (column().columnControl.searchClear() method)
|
|
1513
|
+
dt.on('cc-search-clear.DT', function (e, colIdx) {
|
|
1315
1514
|
if (colIdx === _this._idx) {
|
|
1316
1515
|
// Don't want an automatic redraw on this event
|
|
1317
1516
|
_this._loadingState = true;
|
|
@@ -1319,6 +1518,27 @@ var SearchInput = /** @class */ (function () {
|
|
|
1319
1518
|
_this._loadingState = false;
|
|
1320
1519
|
}
|
|
1321
1520
|
});
|
|
1521
|
+
// Data for server-side processing
|
|
1522
|
+
if (dt.page.info().serverSide) {
|
|
1523
|
+
dt.on('preXhr.DT', function (e, s, d) {
|
|
1524
|
+
// The column has been removed from the submit data - can't do anything
|
|
1525
|
+
if (!d.columns || !d.columns[_this._idx]) {
|
|
1526
|
+
return;
|
|
1527
|
+
}
|
|
1528
|
+
if (!d.columns[_this._idx].columnControl) {
|
|
1529
|
+
d.columns[_this._idx].columnControl = {};
|
|
1530
|
+
}
|
|
1531
|
+
var val = _this._dom.input.value;
|
|
1532
|
+
if (_this._sspTransform) {
|
|
1533
|
+
val = _this._sspTransform(val);
|
|
1534
|
+
}
|
|
1535
|
+
d.columns[_this._idx].columnControl.search = Object.assign({
|
|
1536
|
+
value: val,
|
|
1537
|
+
logic: _this._dom.select.value,
|
|
1538
|
+
type: _this._type
|
|
1539
|
+
}, _this._sspData);
|
|
1540
|
+
});
|
|
1541
|
+
}
|
|
1322
1542
|
}
|
|
1323
1543
|
/**
|
|
1324
1544
|
* Add a class to the container
|
|
@@ -1441,6 +1661,26 @@ var SearchInput = /** @class */ (function () {
|
|
|
1441
1661
|
this.runSearch();
|
|
1442
1662
|
return this;
|
|
1443
1663
|
};
|
|
1664
|
+
/**
|
|
1665
|
+
* Set a function to transform the input value before SSP data submission
|
|
1666
|
+
*
|
|
1667
|
+
* @param fn Transform function
|
|
1668
|
+
* @returns Self for chaining
|
|
1669
|
+
*/
|
|
1670
|
+
SearchInput.prototype.sspTransform = function (fn) {
|
|
1671
|
+
this._sspTransform = fn;
|
|
1672
|
+
return this;
|
|
1673
|
+
};
|
|
1674
|
+
/**
|
|
1675
|
+
* Set extra information to be send to the server for server-side processing
|
|
1676
|
+
*
|
|
1677
|
+
* @param data Data object
|
|
1678
|
+
* @returns Self for chaining
|
|
1679
|
+
*/
|
|
1680
|
+
SearchInput.prototype.sspData = function (data) {
|
|
1681
|
+
this._sspData = data;
|
|
1682
|
+
return this;
|
|
1683
|
+
};
|
|
1444
1684
|
/**
|
|
1445
1685
|
* Set the text that will be shown as the title for the control
|
|
1446
1686
|
*
|
|
@@ -1503,6 +1743,8 @@ var SearchInput = /** @class */ (function () {
|
|
|
1503
1743
|
var searchDateTime = {
|
|
1504
1744
|
defaults: {
|
|
1505
1745
|
clear: true,
|
|
1746
|
+
format: '',
|
|
1747
|
+
mask: '',
|
|
1506
1748
|
placeholder: '',
|
|
1507
1749
|
title: '',
|
|
1508
1750
|
titleAttr: ''
|
|
@@ -1514,11 +1756,14 @@ var searchDateTime = {
|
|
|
1514
1756
|
var luxon = DataTable.use('luxon');
|
|
1515
1757
|
var dt = this.dt();
|
|
1516
1758
|
var i18nBase = 'columnControl.search.datetime.';
|
|
1517
|
-
var
|
|
1759
|
+
var pickerFormat = '';
|
|
1760
|
+
var dataSrcFormat = '';
|
|
1518
1761
|
var dateTime;
|
|
1519
1762
|
var searchInput = new SearchInput(dt, this.idx())
|
|
1520
1763
|
.type('date')
|
|
1521
1764
|
.addClass('dtcc-searchDateTime')
|
|
1765
|
+
.sspTransform(function (val) { return toISO(val, pickerFormat, moment, luxon); })
|
|
1766
|
+
.sspData({ mask: config.mask })
|
|
1522
1767
|
.clearable(config.clear)
|
|
1523
1768
|
.placeholder(config.placeholder)
|
|
1524
1769
|
.title(config.title)
|
|
@@ -1532,10 +1777,18 @@ var searchDateTime = {
|
|
|
1532
1777
|
{ label: dt.i18n(i18nBase + 'notEmpty', 'Not empty'), value: 'notEmpty' }
|
|
1533
1778
|
])
|
|
1534
1779
|
.search(function (searchType, searchTerm, loadingState) {
|
|
1780
|
+
// When SSP, don't apply a filter here, SearchInput will add to the submit data
|
|
1781
|
+
if (dt.page.info().serverSide) {
|
|
1782
|
+
if (!loadingState) {
|
|
1783
|
+
dt.draw();
|
|
1784
|
+
}
|
|
1785
|
+
return;
|
|
1786
|
+
}
|
|
1787
|
+
var mask = config.mask;
|
|
1535
1788
|
var column = dt.column(_this.idx());
|
|
1536
1789
|
var search = searchTerm === ''
|
|
1537
1790
|
? ''
|
|
1538
|
-
: dateToNum(dateTime && fromPicker ? dateTime.val() : searchTerm.trim(),
|
|
1791
|
+
: dateToNum(dateTime && fromPicker ? dateTime.val() : searchTerm.trim(), pickerFormat, moment, luxon, mask);
|
|
1539
1792
|
if (searchType === 'empty') {
|
|
1540
1793
|
column.search.fixed('dtcc', function (haystack) { return !haystack; });
|
|
1541
1794
|
}
|
|
@@ -1554,16 +1807,24 @@ var searchDateTime = {
|
|
|
1554
1807
|
// Use a function for matching - weak typing
|
|
1555
1808
|
// Note that the haystack in the search function is the rendered date - it
|
|
1556
1809
|
// might need to be converted back to a date
|
|
1557
|
-
column.search.fixed('dtcc', function (haystack) {
|
|
1810
|
+
column.search.fixed('dtcc', function (haystack) {
|
|
1811
|
+
return dateToNum(haystack, dataSrcFormat, moment, luxon, mask) == search;
|
|
1812
|
+
});
|
|
1558
1813
|
}
|
|
1559
1814
|
else if (searchType === 'notEqual') {
|
|
1560
|
-
column.search.fixed('dtcc', function (haystack) {
|
|
1815
|
+
column.search.fixed('dtcc', function (haystack) {
|
|
1816
|
+
return dateToNum(haystack, dataSrcFormat, moment, luxon, mask) != search;
|
|
1817
|
+
});
|
|
1561
1818
|
}
|
|
1562
1819
|
else if (searchType === 'greater') {
|
|
1563
|
-
column.search.fixed('dtcc', function (haystack) {
|
|
1820
|
+
column.search.fixed('dtcc', function (haystack) {
|
|
1821
|
+
return dateToNum(haystack, dataSrcFormat, moment, luxon, mask) > search;
|
|
1822
|
+
});
|
|
1564
1823
|
}
|
|
1565
1824
|
else if (searchType === 'less') {
|
|
1566
|
-
column.search.fixed('dtcc', function (haystack) {
|
|
1825
|
+
column.search.fixed('dtcc', function (haystack) {
|
|
1826
|
+
return dateToNum(haystack, dataSrcFormat, moment, luxon, mask) < search;
|
|
1827
|
+
});
|
|
1567
1828
|
}
|
|
1568
1829
|
// If in a dropdown, set the parent levels as active
|
|
1569
1830
|
if (config._parents) {
|
|
@@ -1578,10 +1839,13 @@ var searchDateTime = {
|
|
|
1578
1839
|
// Once data has been loaded we can run DateTime with the specified format
|
|
1579
1840
|
dt.ready(function () {
|
|
1580
1841
|
var DateTime = DataTable.use('datetime');
|
|
1581
|
-
|
|
1842
|
+
dataSrcFormat = getFormat(dt, _this.idx());
|
|
1843
|
+
pickerFormat = config.format
|
|
1844
|
+
? config.format
|
|
1845
|
+
: dataSrcFormat;
|
|
1582
1846
|
if (DateTime) {
|
|
1583
1847
|
dateTime = new DateTime(searchInput.input(), {
|
|
1584
|
-
format:
|
|
1848
|
+
format: pickerFormat,
|
|
1585
1849
|
i18n: dt.settings()[0].oLanguage.datetime, // could be undefined
|
|
1586
1850
|
onChange: function () {
|
|
1587
1851
|
fromPicker = true;
|
|
@@ -1608,18 +1872,36 @@ function getFormat(dt, column) {
|
|
|
1608
1872
|
return 'YYYY-MM-DD';
|
|
1609
1873
|
}
|
|
1610
1874
|
else if (type === 'datetime') {
|
|
1611
|
-
// If no format was specified in the DT type,
|
|
1612
|
-
//
|
|
1613
|
-
|
|
1614
|
-
var
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
.
|
|
1875
|
+
// If no format was specified in the DT type, a Javascript native toLocaleDateString
|
|
1876
|
+
// was used. Need to work out what that format is in Moment or Luxon. We need to pass
|
|
1877
|
+
// a known value though the renderer and work out the format
|
|
1878
|
+
var renderer = dt.settings()[0].aoColumns[column].mRender;
|
|
1879
|
+
var resultPm = renderer('1999-08-07T23:05:04Z', 'display');
|
|
1880
|
+
var resultAm = renderer('1999-08-07T03:05:04Z', 'display');
|
|
1881
|
+
var leadingZero = resultAm.includes('03');
|
|
1882
|
+
// What formatter are we using?
|
|
1883
|
+
if (DataTable.use('moment')) {
|
|
1884
|
+
return resultPm
|
|
1885
|
+
.replace('23', leadingZero ? 'HH' : 'H')
|
|
1886
|
+
.replace('11', leadingZero ? 'hh' : 'h')
|
|
1887
|
+
.replace('05', 'mm')
|
|
1888
|
+
.replace('04', 'ss')
|
|
1889
|
+
.replace('PM', 'A')
|
|
1890
|
+
.replace('pm', 'a')
|
|
1891
|
+
.replace('07', 'DD')
|
|
1892
|
+
.replace('7', 'D')
|
|
1893
|
+
.replace('08', 'MM')
|
|
1894
|
+
.replace('8', 'M')
|
|
1895
|
+
.replace('1999', 'YYYY')
|
|
1896
|
+
.replace('99', 'YY');
|
|
1897
|
+
}
|
|
1898
|
+
else if (DataTable.use('luxon')) {
|
|
1899
|
+
return resultPm
|
|
1900
|
+
.replace('23', leadingZero ? 'HH' : 'H')
|
|
1901
|
+
.replace('11', leadingZero ? 'hh' : 'h')
|
|
1902
|
+
.replace('05', 'mm')
|
|
1903
|
+
.replace('04', 'ss')
|
|
1904
|
+
.replace('PM', 'a')
|
|
1623
1905
|
.replace('07', 'dd')
|
|
1624
1906
|
.replace('7', 'd')
|
|
1625
1907
|
.replace('08', 'MM')
|
|
@@ -1627,6 +1909,13 @@ function getFormat(dt, column) {
|
|
|
1627
1909
|
.replace('1999', 'yyyy')
|
|
1628
1910
|
.replace('99', 'yy');
|
|
1629
1911
|
}
|
|
1912
|
+
else if (resultPm.includes('23') && resultPm.includes('1999')) {
|
|
1913
|
+
return 'YYYY-MM-DD hh:mm:ss';
|
|
1914
|
+
}
|
|
1915
|
+
else if (resultPm.includes('23')) {
|
|
1916
|
+
return 'hh:mm:ss';
|
|
1917
|
+
}
|
|
1918
|
+
// fall through to final return
|
|
1630
1919
|
}
|
|
1631
1920
|
else if (type.includes('datetime-')) {
|
|
1632
1921
|
// Column was specified with a particular display format - we can extract that format from
|
|
@@ -1650,19 +1939,75 @@ function getFormat(dt, column) {
|
|
|
1650
1939
|
* @param luxon Luxon object, if it is available
|
|
1651
1940
|
* @returns Time stamp - milliseconds
|
|
1652
1941
|
*/
|
|
1653
|
-
function dateToNum(input, srcFormat, moment, luxon) {
|
|
1942
|
+
function dateToNum(input, srcFormat, moment, luxon, mask) {
|
|
1943
|
+
var d;
|
|
1654
1944
|
if (input === '') {
|
|
1655
1945
|
return '';
|
|
1656
1946
|
}
|
|
1657
|
-
|
|
1658
|
-
|
|
1947
|
+
if (input instanceof Date) {
|
|
1948
|
+
d = input;
|
|
1659
1949
|
}
|
|
1660
1950
|
else if (srcFormat !== 'YYYY-MM-DD' && (moment || luxon)) {
|
|
1661
|
-
|
|
1951
|
+
d = new Date(moment
|
|
1662
1952
|
? moment(input, srcFormat).unix() * 1000
|
|
1663
|
-
: luxon.DateTime.fromFormat(input, srcFormat).toMillis();
|
|
1953
|
+
: luxon.DateTime.fromFormat(input, srcFormat).toMillis());
|
|
1664
1954
|
}
|
|
1665
|
-
|
|
1955
|
+
else {
|
|
1956
|
+
// new Date() with `/` separators will treat the input as local time, but with `-` it will
|
|
1957
|
+
// treat it as UTC. We want UTC so do a replacement
|
|
1958
|
+
d = new Date(input.replace(/\//g, '-'));
|
|
1959
|
+
}
|
|
1960
|
+
if (mask) {
|
|
1961
|
+
if (!mask.includes('YYYY')) {
|
|
1962
|
+
d.setFullYear(1970);
|
|
1963
|
+
}
|
|
1964
|
+
if (!mask.includes('MM')) {
|
|
1965
|
+
d.setUTCMonth(0);
|
|
1966
|
+
}
|
|
1967
|
+
if (!mask.includes('DD')) {
|
|
1968
|
+
d.setUTCDate(1);
|
|
1969
|
+
}
|
|
1970
|
+
if (!mask.includes('hh')) {
|
|
1971
|
+
d.setUTCHours(0);
|
|
1972
|
+
}
|
|
1973
|
+
if (!mask.includes('mm')) {
|
|
1974
|
+
d.setUTCMinutes(0);
|
|
1975
|
+
}
|
|
1976
|
+
if (!mask.includes('ss')) {
|
|
1977
|
+
// This will match milliseconds as well, but that's fine, you won't match mS but not S
|
|
1978
|
+
d.setUTCSeconds(0);
|
|
1979
|
+
}
|
|
1980
|
+
if (!mask.includes('sss')) {
|
|
1981
|
+
d.setUTCMilliseconds(0);
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
return d.getTime();
|
|
1985
|
+
}
|
|
1986
|
+
/**
|
|
1987
|
+
* Convert an input string to an ISO formatted date
|
|
1988
|
+
*
|
|
1989
|
+
* @param input Input value
|
|
1990
|
+
* @param srcFormat String format of the input
|
|
1991
|
+
* @param moment Moment instance, if it is available
|
|
1992
|
+
* @param luxon Luxon object, if it is available
|
|
1993
|
+
* @returns Value in ISO
|
|
1994
|
+
*/
|
|
1995
|
+
function toISO(input, srcFormat, moment, luxon) {
|
|
1996
|
+
if (input === '') {
|
|
1997
|
+
return '';
|
|
1998
|
+
}
|
|
1999
|
+
else if (srcFormat !== 'YYYY-MM-DD' && moment) {
|
|
2000
|
+
// TODO Does it have a time component?
|
|
2001
|
+
return moment.utc(input, srcFormat).toISOString();
|
|
2002
|
+
}
|
|
2003
|
+
else if (srcFormat !== 'YYYY-MM-DD' && luxon) {
|
|
2004
|
+
// TODO Does it have a time component?
|
|
2005
|
+
return luxon.DateTime.fromFormat(input, srcFormat).toISO();
|
|
2006
|
+
}
|
|
2007
|
+
// new Date() with `/` separators will treat the input as local time, but with `-` it will
|
|
2008
|
+
// treat it as UTC. We want UTC so do a replacement
|
|
2009
|
+
input = input.replace(/\//g, '-');
|
|
2010
|
+
return input;
|
|
1666
2011
|
}
|
|
1667
2012
|
|
|
1668
2013
|
/** Set the options to show in the list */
|
|
@@ -1740,7 +2085,7 @@ function reloadOptions(dt, config, idx, checkList, loadedValues) {
|
|
|
1740
2085
|
// No point in doing any further processing here
|
|
1741
2086
|
return;
|
|
1742
2087
|
}
|
|
1743
|
-
else {
|
|
2088
|
+
else if (!dt.page.info().serverSide) {
|
|
1744
2089
|
// Either no ajax object (i.e. not an Ajax table), or no matching ajax options
|
|
1745
2090
|
// for this column - get the values for the column, taking into account
|
|
1746
2091
|
// orthogonal rendering
|
|
@@ -1786,6 +2131,10 @@ var searchList = {
|
|
|
1786
2131
|
// The search can be applied from a stored start at start up before the options are
|
|
1787
2132
|
// available. It can also be applied by user input, so it is generalised into this function.
|
|
1788
2133
|
var applySearch = function (values) {
|
|
2134
|
+
// When SSP, don't do any client-side filtering
|
|
2135
|
+
if (dt.page.info().serverSide) {
|
|
2136
|
+
return;
|
|
2137
|
+
}
|
|
1789
2138
|
var col = dt.column(_this.idx());
|
|
1790
2139
|
if (!values) {
|
|
1791
2140
|
return;
|
|
@@ -1805,11 +2154,11 @@ var searchList = {
|
|
|
1805
2154
|
config._parents.forEach(function (btn) { return btn.activeList(_this.unique(), !!values.length); });
|
|
1806
2155
|
}
|
|
1807
2156
|
};
|
|
1808
|
-
var checkList = new CheckList(dt, {
|
|
2157
|
+
var checkList = new CheckList(dt, this, {
|
|
1809
2158
|
search: config.search,
|
|
1810
2159
|
select: config.select
|
|
1811
2160
|
})
|
|
1812
|
-
.searchListener(dt
|
|
2161
|
+
.searchListener(dt)
|
|
1813
2162
|
.title(dt
|
|
1814
2163
|
.i18n('columnControl.searchList', config.title)
|
|
1815
2164
|
.replace('[title]', dt.column(this.idx()).title()))
|
|
@@ -1829,14 +2178,28 @@ var searchList = {
|
|
|
1829
2178
|
dt.ready(function () {
|
|
1830
2179
|
reloadOptions(dt, config, _this.idx(), checkList, loadedValues);
|
|
1831
2180
|
});
|
|
2181
|
+
// Xhr event listener for updates of options
|
|
2182
|
+
dt.on('xhr', function (e, s, json) {
|
|
2183
|
+
// Need to wait for the draw to complete so the table has the latest data
|
|
2184
|
+
dt.one('draw', function () {
|
|
2185
|
+
reloadOptions(dt, config, _this.idx(), checkList, loadedValues);
|
|
2186
|
+
});
|
|
2187
|
+
});
|
|
1832
2188
|
}
|
|
1833
|
-
//
|
|
1834
|
-
dt.
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
2189
|
+
// Data for server-side processing
|
|
2190
|
+
if (dt.page.info().serverSide) {
|
|
2191
|
+
dt.on('preXhr.DT', function (e, s, d) {
|
|
2192
|
+
// The column has been removed from the submit data - can't do anything
|
|
2193
|
+
if (!d.columns || !d.columns[_this.idx()]) {
|
|
2194
|
+
return;
|
|
2195
|
+
}
|
|
2196
|
+
if (!d.columns[_this.idx()].columnControl) {
|
|
2197
|
+
d.columns[_this.idx()].columnControl = {};
|
|
2198
|
+
}
|
|
2199
|
+
// We need the indexes in the HTTP parameter names (for .NET), so use an object.
|
|
2200
|
+
d.columns[_this.idx()].columnControl.list = Object.assign({}, checkList.values());
|
|
1838
2201
|
});
|
|
1839
|
-
}
|
|
2202
|
+
}
|
|
1840
2203
|
// Unlike the SearchInput based search contents, CheckList does not handle state saving
|
|
1841
2204
|
// (since the mechanism for column visibility is different), so state saving is handled
|
|
1842
2205
|
// here.
|
|
@@ -1844,6 +2207,7 @@ var searchList = {
|
|
|
1844
2207
|
var values = getState(_this.idx(), state);
|
|
1845
2208
|
if (values) {
|
|
1846
2209
|
checkList.values(values);
|
|
2210
|
+
applySearch(values);
|
|
1847
2211
|
}
|
|
1848
2212
|
});
|
|
1849
2213
|
dt.on('stateSaveParams', function (e, s, data) {
|
|
@@ -1861,6 +2225,14 @@ var searchList = {
|
|
|
1861
2225
|
? checkList.values()
|
|
1862
2226
|
: loadedValues;
|
|
1863
2227
|
});
|
|
2228
|
+
dt.settings()[0].aoColumns[this.idx()].columnControlSearchList = function (options) {
|
|
2229
|
+
if (options === 'refresh') {
|
|
2230
|
+
reloadOptions(dt, config, _this.idx(), checkList, null);
|
|
2231
|
+
}
|
|
2232
|
+
else {
|
|
2233
|
+
setOptions(checkList, options);
|
|
2234
|
+
}
|
|
2235
|
+
};
|
|
1864
2236
|
loadedValues = getState(this.idx(), dt.state.loaded());
|
|
1865
2237
|
applySearch(loadedValues);
|
|
1866
2238
|
return checkList.element();
|
|
@@ -1899,6 +2271,13 @@ var searchNumber = {
|
|
|
1899
2271
|
{ label: dt.i18n(i18nBase + 'notEmpty', 'Not empty'), value: 'notEmpty' }
|
|
1900
2272
|
])
|
|
1901
2273
|
.search(function (searchType, searchTerm, loadingState) {
|
|
2274
|
+
// When SSP, don't apply a filter here, SearchInput will add to the submit data
|
|
2275
|
+
if (dt.page.info().serverSide) {
|
|
2276
|
+
if (!loadingState) {
|
|
2277
|
+
dt.draw();
|
|
2278
|
+
}
|
|
2279
|
+
return;
|
|
2280
|
+
}
|
|
1902
2281
|
var column = dt.column(_this.idx());
|
|
1903
2282
|
if (searchType === 'empty') {
|
|
1904
2283
|
column.search.fixed('dtcc', function (haystack) { return !haystack; });
|
|
@@ -1996,6 +2375,13 @@ var searchText = {
|
|
|
1996
2375
|
{ label: dt.i18n(i18nBase + 'notEmpty', 'Not empty'), value: 'notEmpty' }
|
|
1997
2376
|
])
|
|
1998
2377
|
.search(function (searchType, searchTerm, loadingState) {
|
|
2378
|
+
// When SSP, don't apply a filter here, SearchInput will add to the submit data
|
|
2379
|
+
if (dt.page.info().serverSide) {
|
|
2380
|
+
if (!loadingState) {
|
|
2381
|
+
dt.draw();
|
|
2382
|
+
}
|
|
2383
|
+
return;
|
|
2384
|
+
}
|
|
1999
2385
|
var column = dt.column(_this.idx());
|
|
2000
2386
|
searchTerm = searchTerm.toLowerCase();
|
|
2001
2387
|
if (searchType === 'empty') {
|
|
@@ -2102,7 +2488,7 @@ var search = {
|
|
|
2102
2488
|
}
|
|
2103
2489
|
};
|
|
2104
2490
|
|
|
2105
|
-
var searchClear = {
|
|
2491
|
+
var searchClear$1 = {
|
|
2106
2492
|
defaults: {
|
|
2107
2493
|
className: 'searchClear',
|
|
2108
2494
|
icon: 'searchClear',
|
|
@@ -2111,12 +2497,12 @@ var searchClear = {
|
|
|
2111
2497
|
init: function (config) {
|
|
2112
2498
|
var _this = this;
|
|
2113
2499
|
var dt = this.dt();
|
|
2114
|
-
var btn = new Button(dt)
|
|
2500
|
+
var btn = new Button(dt, this)
|
|
2115
2501
|
.text(dt.i18n('columnControl.searchClear', config.text))
|
|
2116
2502
|
.icon(config.icon)
|
|
2117
2503
|
.className(config.className)
|
|
2118
2504
|
.handler(function () {
|
|
2119
|
-
dt.column(_this.idx()).
|
|
2505
|
+
dt.column(_this.idx()).columnControl.searchClear().draw();
|
|
2120
2506
|
})
|
|
2121
2507
|
.enable(false);
|
|
2122
2508
|
dt.on('draw', function () {
|
|
@@ -2138,6 +2524,7 @@ var searchDropdown = {
|
|
|
2138
2524
|
columns: '',
|
|
2139
2525
|
hidable: true,
|
|
2140
2526
|
options: null,
|
|
2527
|
+
orthogonal: 'display',
|
|
2141
2528
|
placeholder: '',
|
|
2142
2529
|
search: true,
|
|
2143
2530
|
select: true,
|
|
@@ -2194,6 +2581,10 @@ var contentTypes = {
|
|
|
2194
2581
|
reorder: reorder,
|
|
2195
2582
|
reorderLeft: reorderLeft,
|
|
2196
2583
|
reorderRight: reorderRight,
|
|
2584
|
+
rowGroup: rowGroup,
|
|
2585
|
+
rowGroupAdd: rowGroupAdd,
|
|
2586
|
+
rowGroupClear: rowGroupClear,
|
|
2587
|
+
rowGroupRemove: rowGroupRemove,
|
|
2197
2588
|
order: order,
|
|
2198
2589
|
orderAddAsc: orderAddAsc,
|
|
2199
2590
|
orderAddDesc: orderAddDesc,
|
|
@@ -2203,7 +2594,7 @@ var contentTypes = {
|
|
|
2203
2594
|
orderRemove: orderRemove,
|
|
2204
2595
|
orderStatus: orderStatus,
|
|
2205
2596
|
search: search,
|
|
2206
|
-
searchClear: searchClear,
|
|
2597
|
+
searchClear: searchClear$1,
|
|
2207
2598
|
searchDropdown: searchDropdown,
|
|
2208
2599
|
searchDateTime: searchDateTime,
|
|
2209
2600
|
searchList: searchList,
|
|
@@ -2233,7 +2624,8 @@ var ColumnControl = /** @class */ (function () {
|
|
|
2233
2624
|
this._c = {};
|
|
2234
2625
|
this._s = {
|
|
2235
2626
|
columnIdx: null,
|
|
2236
|
-
unique: null
|
|
2627
|
+
unique: null,
|
|
2628
|
+
toDestroy: []
|
|
2237
2629
|
};
|
|
2238
2630
|
this._dt = dt;
|
|
2239
2631
|
this._s.columnIdx = columnIdx;
|
|
@@ -2259,10 +2651,33 @@ var ColumnControl = /** @class */ (function () {
|
|
|
2259
2651
|
_this._dom.wrapper.appendChild(el);
|
|
2260
2652
|
});
|
|
2261
2653
|
dt.on('destroy', function () {
|
|
2654
|
+
_this._s.toDestroy.slice().forEach(function (el) {
|
|
2655
|
+
el.destroy();
|
|
2656
|
+
});
|
|
2262
2657
|
_this._dom.wrapper.remove();
|
|
2263
2658
|
});
|
|
2264
2659
|
}
|
|
2265
2660
|
}
|
|
2661
|
+
/**
|
|
2662
|
+
* Add a component to the destroy list. This is so there is a single destroy event handler,
|
|
2663
|
+
* which is much better for performance.
|
|
2664
|
+
*
|
|
2665
|
+
* @param component Any instance with a `destroy` method
|
|
2666
|
+
*/
|
|
2667
|
+
ColumnControl.prototype.destroyAdd = function (component) {
|
|
2668
|
+
this._s.toDestroy.push(component);
|
|
2669
|
+
};
|
|
2670
|
+
/**
|
|
2671
|
+
* Remove an instance from the destroy list (it has been destroyed itself)
|
|
2672
|
+
*
|
|
2673
|
+
* @param component Any instance with a `destroy` method
|
|
2674
|
+
*/
|
|
2675
|
+
ColumnControl.prototype.destroyRemove = function (component) {
|
|
2676
|
+
var idx = this._s.toDestroy.indexOf(component);
|
|
2677
|
+
if (idx !== -1) {
|
|
2678
|
+
this._s.toDestroy.splice(idx, 1);
|
|
2679
|
+
}
|
|
2680
|
+
};
|
|
2266
2681
|
/**
|
|
2267
2682
|
* Get the DataTables API instance that hosts this instance of ColumnControl
|
|
2268
2683
|
*
|
|
@@ -2373,7 +2788,7 @@ var ColumnControl = /** @class */ (function () {
|
|
|
2373
2788
|
/** SVG icons that can be used by the content plugins */
|
|
2374
2789
|
ColumnControl.icons = icons;
|
|
2375
2790
|
/** Version */
|
|
2376
|
-
ColumnControl.version = '1.
|
|
2791
|
+
ColumnControl.version = '1.1.1';
|
|
2377
2792
|
return ColumnControl;
|
|
2378
2793
|
}());
|
|
2379
2794
|
|
|
@@ -2445,12 +2860,23 @@ $(document).on('preInit.dt', function (e, settings) {
|
|
|
2445
2860
|
}
|
|
2446
2861
|
});
|
|
2447
2862
|
});
|
|
2448
|
-
|
|
2863
|
+
function searchClear() {
|
|
2449
2864
|
var ctx = this;
|
|
2450
2865
|
return this.iterator('column', function (settings, idx) {
|
|
2451
2866
|
// Note that the listeners for this will not redraw the table.
|
|
2452
2867
|
ctx.trigger('cc-search-clear', [idx]);
|
|
2453
2868
|
});
|
|
2869
|
+
}
|
|
2870
|
+
DataTable.Api.registerPlural('columns().columnControl.searchClear()', 'column().columnControl.searchClear()', searchClear);
|
|
2871
|
+
// Legacy (1.0.x)) - was never documented, but was mentioned in the forum
|
|
2872
|
+
DataTable.Api.registerPlural('columns().ccSearchClear()', 'column().ccSearchClear()', searchClear);
|
|
2873
|
+
DataTable.Api.registerPlural('columns().columnControl.searchList()', 'column().columnControl.searchList()', function (options) {
|
|
2874
|
+
return this.iterator('column', function (settings, idx) {
|
|
2875
|
+
var fn = settings.aoColumns[idx].columnControlSearchList;
|
|
2876
|
+
if (fn) {
|
|
2877
|
+
fn(options);
|
|
2878
|
+
}
|
|
2879
|
+
});
|
|
2454
2880
|
});
|
|
2455
2881
|
DataTable.ext.buttons.ccSearchClear = {
|
|
2456
2882
|
text: function (dt) {
|
|
@@ -2458,7 +2884,7 @@ DataTable.ext.buttons.ccSearchClear = {
|
|
|
2458
2884
|
},
|
|
2459
2885
|
init: function (dt, node, config) {
|
|
2460
2886
|
var _this = this;
|
|
2461
|
-
dt.on('draw', function () {
|
|
2887
|
+
dt.on('draw.DT', function () {
|
|
2462
2888
|
var enabled = false;
|
|
2463
2889
|
var glob = !!dt.search();
|
|
2464
2890
|
// No point in wasting clock cycles if we already know it will be enabled
|
|
@@ -2475,7 +2901,7 @@ DataTable.ext.buttons.ccSearchClear = {
|
|
|
2475
2901
|
},
|
|
2476
2902
|
action: function (e, dt, node, config) {
|
|
2477
2903
|
dt.search('');
|
|
2478
|
-
dt.columns().
|
|
2904
|
+
dt.columns().columnControl.searchClear();
|
|
2479
2905
|
dt.draw();
|
|
2480
2906
|
}
|
|
2481
2907
|
};
|
|
@@ -2637,9 +3063,7 @@ function identifyTargets(targets, input) {
|
|
|
2637
3063
|
* @returns true if it is a config object
|
|
2638
3064
|
*/
|
|
2639
3065
|
function isIConfig(item) {
|
|
2640
|
-
return typeof item === 'object' && item.target !== undefined
|
|
2641
|
-
? true
|
|
2642
|
-
: false;
|
|
3066
|
+
return typeof item === 'object' && item.target !== undefined ? true : false;
|
|
2643
3067
|
}
|
|
2644
3068
|
/**
|
|
2645
3069
|
* Determine if an array contains only content items or not
|