datatables.net-searchbuilder 1.7.1 → 1.8.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
- /*! SearchBuilder 1.7.1
1
+ /*! SearchBuilder 1.8.1
2
2
  * ©SpryMedia Ltd - datatables.net/license/mit
3
3
  */
4
4
 
@@ -52,12 +52,20 @@ var DataTable = $.fn.dataTable;
52
52
  'use strict';
53
53
 
54
54
  var $$3;
55
- var dataTable$3;
55
+ var dataTable$2;
56
+ /** Get a moment object. Attempt to get from DataTables for module loading first. */
56
57
  function moment() {
57
- return window.moment;
58
+ var used = DataTable.use('moment');
59
+ return used
60
+ ? used
61
+ : window.moment;
58
62
  }
63
+ /** Get a luxon object. Attempt to get from DataTables for module loading first. */
59
64
  function luxon() {
60
- return window.luxon;
65
+ var used = DataTable.use('luxon');
66
+ return used
67
+ ? used
68
+ : window.luxon;
61
69
  }
62
70
  /**
63
71
  * Sets the value of jQuery for use in the file
@@ -66,7 +74,7 @@ var DataTable = $.fn.dataTable;
66
74
  */
67
75
  function setJQuery$2(jq) {
68
76
  $$3 = jq;
69
- dataTable$3 = jq.fn.dataTable;
77
+ dataTable$2 = jq.fn.dataTable;
70
78
  }
71
79
  /**
72
80
  * The Criteria class is used within SearchBuilder to represent a search criteria
@@ -78,10 +86,6 @@ var DataTable = $.fn.dataTable;
78
86
  if (serverData === void 0) { serverData = undefined; }
79
87
  if (liveSearch === void 0) { liveSearch = false; }
80
88
  var _this = this;
81
- // Check that the required version of DataTables is included
82
- if (!dataTable$3 || !dataTable$3.versionCheck || !dataTable$3.versionCheck('1.10.0')) {
83
- throw new Error('SearchPane requires DataTables 1.10 or newer');
84
- }
85
89
  this.classes = $$3.extend(true, {}, Criteria.classes);
86
90
  // Get options from user and any extra conditions/column types defined by plug-ins
87
91
  this.c = $$3.extend(true, {}, Criteria.defaults, $$3.fn.dataTable.ext.searchBuilder, opts);
@@ -170,7 +174,7 @@ var DataTable = $.fn.dataTable;
170
174
  val.addClass(this.classes.greyscale);
171
175
  }
172
176
  }
173
- $$3(window).on('resize.dtsb', dataTable$3.util.throttle(function () {
177
+ $$3(window).on('resize.dtsb', dataTable$2.util.throttle(function () {
174
178
  _this.s.topGroup.trigger('dtsb-redrawLogic');
175
179
  }));
176
180
  this._buildCriteria();
@@ -272,7 +276,8 @@ var DataTable = $.fn.dataTable;
272
276
  if (this.s.condition !== undefined && condition !== undefined) {
273
277
  var filter = rowData[this.s.dataIdx];
274
278
  // This check is in place for if a custom decimal character is in place
275
- if (this.s.type.includes('num') &&
279
+ if (this.s.type &&
280
+ this.s.type.includes('num') &&
276
281
  (settings.oLanguage.sDecimal !== '' ||
277
282
  settings.oLanguage.sThousands !== '')) {
278
283
  var splitRD = [rowData[this.s.dataIdx]];
@@ -328,7 +333,7 @@ var DataTable = $.fn.dataTable;
328
333
  var settings = this.s.dt.settings()[0];
329
334
  // This check is in place for if a custom decimal character is in place
330
335
  if (this.s.type !== null &&
331
- this.s.type.includes('num') &&
336
+ ["num", "num-fmt", "html-num", "html-num-fmt"].includes(this.s.type) &&
332
337
  (settings.oLanguage.sDecimal !== '' || settings.oLanguage.sThousands !== '')) {
333
338
  for (i = 0; i < this.s.value.length; i++) {
334
339
  var splitRD = [this.s.value[i].toString()];
@@ -371,7 +376,7 @@ var DataTable = $.fn.dataTable;
371
376
  }
372
377
  }
373
378
  }
374
- if (this.s.type.includes('num') && this.s.dt.page.info().serverSide) {
379
+ if (this.s.type && this.s.type.includes('num') && this.s.dt.page.info().serverSide) {
375
380
  for (i = 0; i < this.s.value.length; i++) {
376
381
  this.s.value[i] = this.s.value[i].replace(/[^0-9.\-]/g, '');
377
382
  }
@@ -696,12 +701,13 @@ var DataTable = $.fn.dataTable;
696
701
  Criteria.prototype._populateCondition = function () {
697
702
  var conditionOpts = [];
698
703
  var conditionsLength = Object.keys(this.s.conditions).length;
699
- var colInits = this.s.dt.settings()[0].aoColumns;
704
+ var dt = this.s.dt;
705
+ var colInits = dt.settings()[0].aoColumns;
700
706
  var column = +this.dom.data.children('option:selected').val();
701
707
  var condition, condName;
702
708
  // If there are no conditions stored then we need to get them from the appropriate type
703
709
  if (conditionsLength === 0) {
704
- this.s.type = this.s.dt.column(column).type();
710
+ this.s.type = dt.column(column).type();
705
711
  if (colInits !== undefined) {
706
712
  var colInit = colInits[column];
707
713
  if (colInit.searchBuilderType !== undefined && colInit.searchBuilderType !== null) {
@@ -715,9 +721,9 @@ var DataTable = $.fn.dataTable;
715
721
  if (this.s.type === null || this.s.type === undefined) {
716
722
  // This can only happen in DT1 - DT2 will do the invalidation of the type itself
717
723
  if ($$3.fn.dataTable.ext.oApi) {
718
- $$3.fn.dataTable.ext.oApi._fnColumnTypes(this.s.dt.settings()[0]);
724
+ $$3.fn.dataTable.ext.oApi._fnColumnTypes(dt.settings()[0]);
719
725
  }
720
- this.s.type = this.s.dt.column(column).type();
726
+ this.s.type = dt.column(column).type();
721
727
  }
722
728
  // Enable the condition element
723
729
  this.dom.condition
@@ -727,9 +733,9 @@ var DataTable = $.fn.dataTable;
727
733
  .addClass(this.classes.italic);
728
734
  this.dom.conditionTitle
729
735
  .prop('selected', true);
730
- var decimal = this.s.dt.settings()[0].oLanguage.sDecimal;
736
+ var decimal = dt.settings()[0].oLanguage.sDecimal;
731
737
  // This check is in place for if a custom decimal character is in place
732
- if (decimal !== '' && this.s.type.indexOf(decimal) === this.s.type.length - decimal.length) {
738
+ if (decimal !== '' && this.s.type && this.s.type.indexOf(decimal) === this.s.type.length - decimal.length) {
733
739
  if (this.s.type.includes('num-fmt')) {
734
740
  this.s.type = this.s.type.replace(decimal, '');
735
741
  }
@@ -738,27 +744,36 @@ var DataTable = $.fn.dataTable;
738
744
  }
739
745
  }
740
746
  // Select which conditions are going to be used based on the column type
741
- var conditionObj = this.c.conditions[this.s.type] !== undefined ?
742
- this.c.conditions[this.s.type] :
743
- this.s.type.includes('moment') ?
744
- this.c.conditions.moment :
745
- this.s.type.includes('luxon') ?
746
- this.c.conditions.luxon :
747
- this.c.conditions.string;
748
- // If it is a moment format then extract the date format
749
- if (this.s.type.includes('moment')) {
747
+ var conditionObj = void 0;
748
+ if (this.c.conditions[this.s.type] !== undefined) {
749
+ conditionObj = this.c.conditions[this.s.type];
750
+ }
751
+ else if (this.s.type && this.s.type.includes('datetime-')) {
752
+ // Date / time data types in DataTables are driven by Luxon or
753
+ // Moment.js.
754
+ conditionObj = DataTable.use('moment')
755
+ ? this.c.conditions.moment
756
+ : this.c.conditions.luxon;
757
+ this.s.dateFormat = this.s.type.replace(/datetime-/g, '');
758
+ }
759
+ else if (this.s.type && this.s.type.includes('moment')) {
760
+ conditionObj = this.c.conditions.moment;
750
761
  this.s.dateFormat = this.s.type.replace(/moment-/g, '');
751
762
  }
752
- else if (this.s.type.includes('luxon')) {
763
+ else if (this.s.type && this.s.type.includes('luxon')) {
764
+ conditionObj = this.c.conditions.luxon;
753
765
  this.s.dateFormat = this.s.type.replace(/luxon-/g, '');
754
766
  }
767
+ else {
768
+ conditionObj = this.c.conditions.string;
769
+ }
755
770
  // Add all of the conditions to the select element
756
771
  for (var _i = 0, _a = Object.keys(conditionObj); _i < _a.length; _i++) {
757
772
  condition = _a[_i];
758
773
  if (conditionObj[condition] !== null) {
759
774
  // Serverside processing does not supply the options for the select elements
760
775
  // Instead input elements need to be used for these instead
761
- if (this.s.dt.page.info().serverSide && conditionObj[condition].init === Criteria.initSelect) {
776
+ if (dt.page.info().serverSide && conditionObj[condition].init === Criteria.initSelect) {
762
777
  var col = colInits[column];
763
778
  if (this.s.serverData && this.s.serverData[col.data]) {
764
779
  conditionObj[condition].init = Criteria.initSelectSSP;
@@ -774,7 +789,7 @@ var DataTable = $.fn.dataTable;
774
789
  this.s.conditions[condition] = conditionObj[condition];
775
790
  condName = conditionObj[condition].conditionName;
776
791
  if (typeof condName === 'function') {
777
- condName = condName(this.s.dt, this.c.i18n);
792
+ condName = condName(dt, this.c.i18n);
778
793
  }
779
794
  conditionOpts.push($$3('<option>', {
780
795
  text: condName,
@@ -792,7 +807,7 @@ var DataTable = $.fn.dataTable;
792
807
  condition = _c[_b];
793
808
  var name_1 = this.s.conditions[condition].conditionName;
794
809
  if (typeof name_1 === 'function') {
795
- name_1 = name_1(this.s.dt, this.c.i18n);
810
+ name_1 = name_1(dt, this.c.i18n);
796
811
  }
797
812
  var newOpt = $$3('<option>', {
798
813
  text: name_1,
@@ -835,7 +850,7 @@ var DataTable = $.fn.dataTable;
835
850
  condName = this.s.conditions[cond].conditionName;
836
851
  if (
837
852
  // If the conditionName matches the text of the option
838
- (typeof condName === 'string' ? condName : condName(this.s.dt, this.c.i18n)) ===
853
+ (typeof condName === 'string' ? condName : condName(dt, this.c.i18n)) ===
839
854
  conditionOpts[i].text() &&
840
855
  // and the tokens match
841
856
  cond === defaultCondition) {
@@ -1459,7 +1474,7 @@ var DataTable = $.fn.dataTable;
1459
1474
  values.push(Criteria._escapeHTML(element.val()));
1460
1475
  }
1461
1476
  }
1462
- return values;
1477
+ return values.map(dataTable$2.util.diacritics);
1463
1478
  };
1464
1479
  /**
1465
1480
  * Function that is run on each element as a call back when a search should be triggered
@@ -2419,7 +2434,6 @@ var DataTable = $.fn.dataTable;
2419
2434
  }());
2420
2435
 
2421
2436
  var $$2;
2422
- var dataTable$2;
2423
2437
  /**
2424
2438
  * Sets the value of jQuery for use in the file
2425
2439
  *
@@ -2427,7 +2441,7 @@ var DataTable = $.fn.dataTable;
2427
2441
  */
2428
2442
  function setJQuery$1(jq) {
2429
2443
  $$2 = jq;
2430
- dataTable$2 = jq.fn.dataTable;
2444
+ jq.fn.dataTable;
2431
2445
  }
2432
2446
  /**
2433
2447
  * The Group class is used within SearchBuilder to represent a group of criteria
@@ -2438,10 +2452,6 @@ var DataTable = $.fn.dataTable;
2438
2452
  if (isChild === void 0) { isChild = false; }
2439
2453
  if (depth === void 0) { depth = 1; }
2440
2454
  if (serverData === void 0) { serverData = undefined; }
2441
- // Check that the required version of DataTables is included
2442
- if (!dataTable$2 || !dataTable$2.versionCheck || !dataTable$2.versionCheck('1.10.0')) {
2443
- throw new Error('SearchBuilder requires DataTables 1.10 or newer');
2444
- }
2445
2455
  this.classes = $$2.extend(true, {}, Group.classes);
2446
2456
  // Get options from user
2447
2457
  this.c = $$2.extend(true, {}, Group.defaults, opts);
@@ -3202,8 +3212,8 @@ var DataTable = $.fn.dataTable;
3202
3212
  function SearchBuilder(builderSettings, opts) {
3203
3213
  var _this = this;
3204
3214
  // Check that the required version of DataTables is included
3205
- if (!dataTable$1 || !dataTable$1.versionCheck || !dataTable$1.versionCheck('1.10.0')) {
3206
- throw new Error('SearchBuilder requires DataTables 1.10 or newer');
3215
+ if (!dataTable$1 || !dataTable$1.versionCheck || !dataTable$1.versionCheck('2')) {
3216
+ throw new Error('SearchBuilder requires DataTables 2 or newer');
3207
3217
  }
3208
3218
  var table = new dataTable$1.Api(builderSettings);
3209
3219
  this.classes = $$1.extend(true, {}, SearchBuilder.classes);
@@ -3265,7 +3275,9 @@ var DataTable = $.fn.dataTable;
3265
3275
  // eslint upset at empty object but that is what it is
3266
3276
  SearchBuilder.prototype.getDetails = function (deFormatDates) {
3267
3277
  if (deFormatDates === void 0) { deFormatDates = false; }
3268
- return this.s.topGroup.getDetails(deFormatDates);
3278
+ return this.s.topGroup
3279
+ ? this.s.topGroup.getDetails(deFormatDates)
3280
+ : {};
3269
3281
  };
3270
3282
  /**
3271
3283
  * Getter for the node of the container for the searchBuilder
@@ -3398,9 +3410,7 @@ var DataTable = $.fn.dataTable;
3398
3410
  data.searchBuilder = _this._collapseArray(_this.getDetails(true));
3399
3411
  }
3400
3412
  });
3401
- this.s.dt.on(dataTable$1.versionCheck('2')
3402
- ? 'columns-reordered'
3403
- : 'column-reorder', function () {
3413
+ this.s.dt.on('columns-reordered', function () {
3404
3414
  _this.rebuild(_this.getDetails());
3405
3415
  });
3406
3416
  if (loadState) {
@@ -3615,7 +3625,7 @@ var DataTable = $.fn.dataTable;
3615
3625
  _this.dom.clearAll.remove();
3616
3626
  });
3617
3627
  };
3618
- SearchBuilder.version = '1.7.1';
3628
+ SearchBuilder.version = '1.8.1';
3619
3629
  SearchBuilder.classes = {
3620
3630
  button: 'dtsb-button',
3621
3631
  clearAll: 'dtsb-clearAll',
@@ -3723,7 +3733,7 @@ var DataTable = $.fn.dataTable;
3723
3733
  return SearchBuilder;
3724
3734
  }());
3725
3735
 
3726
- /*! SearchBuilder 1.7.1
3736
+ /*! SearchBuilder 1.8.1
3727
3737
  * ©SpryMedia Ltd - datatables.net/license/mit
3728
3738
  */
3729
3739
  setJQuery($);
@@ -3765,12 +3775,15 @@ var DataTable = $.fn.dataTable;
3765
3775
  },
3766
3776
  config: {},
3767
3777
  init: function (dt, node, config) {
3768
- var sb = new DataTable.SearchBuilder(dt, $.extend({
3769
- filterChanged: function (count, text) {
3770
- dt.button(node).text(text);
3771
- }
3772
- }, config.config));
3773
- dt.button(node).text(config.text || dt.i18n('searchBuilder.button', sb.c.i18n.button, 0));
3778
+ var that = this;
3779
+ var sb = new DataTable.SearchBuilder(dt, config.config);
3780
+ dt.on('draw', function () {
3781
+ var count = sb.s.topGroup
3782
+ ? sb.s.topGroup.count()
3783
+ : 0;
3784
+ that.text(dt.i18n('searchBuilder.button', sb.c.i18n.button, count));
3785
+ });
3786
+ that.text(config.text || dt.i18n('searchBuilder.button', sb.c.i18n.button, 0));
3774
3787
  config._searchBuilder = sb;
3775
3788
  },
3776
3789
  text: null