datatables.net-searchbuilder 1.4.2 → 1.6.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.
@@ -1,10 +1,13 @@
1
- /*! SearchBuilder 1.4.2
1
+ /*! SearchBuilder 1.6.0
2
2
  * ©SpryMedia Ltd - datatables.net/license/mit
3
3
  */
4
4
 
5
- import $ from 'jquery';
5
+ import jQuery from 'jquery';
6
6
  import DataTable from 'datatables.net';
7
7
 
8
+ // Allow reassignment of the $ variable
9
+ let $ = jQuery;
10
+
8
11
  (function () {
9
12
  'use strict';
10
13
 
@@ -29,11 +32,12 @@ import DataTable from 'datatables.net';
29
32
  * The Criteria class is used within SearchBuilder to represent a search criteria
30
33
  */
31
34
  var Criteria = /** @class */ (function () {
32
- function Criteria(table, opts, topGroup, index, depth, serverData) {
35
+ function Criteria(table, opts, topGroup, index, depth, serverData, liveSearch) {
33
36
  var _this = this;
34
37
  if (index === void 0) { index = 0; }
35
38
  if (depth === void 0) { depth = 1; }
36
39
  if (serverData === void 0) { serverData = undefined; }
40
+ if (liveSearch === void 0) { liveSearch = false; }
37
41
  // Check that the required version of DataTables is included
38
42
  if (!dataTable$3 || !dataTable$3.versionCheck || !dataTable$3.versionCheck('1.10.0')) {
39
43
  throw new Error('SearchPane requires DataTables 1.10 or newer');
@@ -53,6 +57,7 @@ import DataTable from 'datatables.net';
53
57
  dt: table,
54
58
  filled: false,
55
59
  index: index,
60
+ liveSearch: liveSearch,
56
61
  origData: undefined,
57
62
  preventRedraw: false,
58
63
  serverData: serverData,
@@ -145,6 +150,16 @@ import DataTable from 'datatables.net';
145
150
  .replace(/>/g, '>')
146
151
  .replace(/"/g, '"');
147
152
  };
153
+ /**
154
+ * Redraw the DataTable with the current search parameters
155
+ */
156
+ Criteria.prototype.doSearch = function () {
157
+ // Only do the search if live search is disabled, otherwise the search
158
+ // is triggered by the button at the top level group.
159
+ if (this.c.liveSearch) {
160
+ this.s.dt.draw();
161
+ }
162
+ };
148
163
  /**
149
164
  * Parses formatted numbers down to a form where they can be compared
150
165
  *
@@ -368,7 +383,7 @@ import DataTable from 'datatables.net';
368
383
  $$3(this).prop('selected', true);
369
384
  data_1.removeClass(italic_1);
370
385
  foundData = true;
371
- dataIdx = $$3(this).val();
386
+ dataIdx = parseInt($$3(this).val(), 10);
372
387
  }
373
388
  else {
374
389
  $$3(this).removeProp('selected');
@@ -450,7 +465,7 @@ import DataTable from 'datatables.net';
450
465
  // remove it from the search and trigger a new search
451
466
  if (_this.s.filled) {
452
467
  _this.s.filled = false;
453
- _this.s.dt.draw();
468
+ _this.doSearch();
454
469
  _this.setListeners();
455
470
  }
456
471
  _this.s.dt.state.save();
@@ -491,13 +506,13 @@ import DataTable from 'datatables.net';
491
506
  // it from the search and trigger a new search
492
507
  if (_this.s.filled && val !== undefined && _this.dom.inputCont.has(val[0]).length !== 0) {
493
508
  _this.s.filled = false;
494
- _this.s.dt.draw();
509
+ _this.doSearch();
495
510
  _this.setListeners();
496
511
  }
497
512
  }
498
513
  if (_this.dom.value.length === 0 ||
499
514
  _this.dom.value.length === 1 && _this.dom.value[0] === undefined) {
500
- _this.s.dt.draw();
515
+ _this.doSearch();
501
516
  }
502
517
  }
503
518
  else {
@@ -885,7 +900,7 @@ import DataTable from 'datatables.net';
885
900
  // If using SSP we want to restrict the amount of server calls that take place
886
901
  // and this will already have taken place
887
902
  if (!this.s.dt.page.info().serverSide) {
888
- this.s.dt.draw();
903
+ this.doSearch();
889
904
  }
890
905
  this.setListeners();
891
906
  }
@@ -1221,13 +1236,15 @@ import DataTable from 'datatables.net';
1221
1236
  Criteria.initDate = function (that, fn, preDefined) {
1222
1237
  if (preDefined === void 0) { preDefined = null; }
1223
1238
  var searchDelay = that.s.dt.settings()[0].searchDelay;
1239
+ var i18n = that.s.dt.i18n('datetime', {});
1224
1240
  // Declare date element using DataTables dateTime plugin
1225
1241
  var el = $$3('<input/>')
1226
1242
  .addClass(Criteria.classes.value)
1227
1243
  .addClass(Criteria.classes.input)
1228
1244
  .dtDateTime({
1229
1245
  attachTo: 'input',
1230
- format: that.s.dateFormat ? that.s.dateFormat : undefined
1246
+ format: that.s.dateFormat ? that.s.dateFormat : undefined,
1247
+ i18n: i18n
1231
1248
  })
1232
1249
  .on('change.dtsb', that._throttle(function () {
1233
1250
  return fn(that, this);
@@ -1262,6 +1279,7 @@ import DataTable from 'datatables.net';
1262
1279
  var _this = this;
1263
1280
  if (preDefined === void 0) { preDefined = null; }
1264
1281
  var searchDelay = that.s.dt.settings()[0].searchDelay;
1282
+ var i18n = that.s.dt.i18n('datetime', {});
1265
1283
  // Declare all of the date elements that are required using DataTables dateTime plugin
1266
1284
  var els = [
1267
1285
  $$3('<input/>')
@@ -1269,7 +1287,8 @@ import DataTable from 'datatables.net';
1269
1287
  .addClass(Criteria.classes.input)
1270
1288
  .dtDateTime({
1271
1289
  attachTo: 'input',
1272
- format: that.s.dateFormat ? that.s.dateFormat : undefined
1290
+ format: that.s.dateFormat ? that.s.dateFormat : undefined,
1291
+ i18n: i18n
1273
1292
  })
1274
1293
  .on('change.dtsb', searchDelay !== null ?
1275
1294
  that.s.dt.settings()[0].oApi._fnThrottle(function () {
@@ -1292,7 +1311,8 @@ import DataTable from 'datatables.net';
1292
1311
  .addClass(Criteria.classes.input)
1293
1312
  .dtDateTime({
1294
1313
  attachTo: 'input',
1295
- format: that.s.dateFormat ? that.s.dateFormat : undefined
1314
+ format: that.s.dateFormat ? that.s.dateFormat : undefined,
1315
+ i18n: i18n
1296
1316
  })
1297
1317
  .on('change.dtsb', searchDelay !== null ?
1298
1318
  that.s.dt.settings()[0].oApi._fnThrottle(function () {
@@ -1402,7 +1422,7 @@ import DataTable from 'datatables.net';
1402
1422
  !(that.s.dt.settings()[0].oInit.search !== undefined &&
1403
1423
  that.s.dt.settings()[0].oInit.search["return"]) ||
1404
1424
  code === 13) {
1405
- that.s.dt.draw();
1425
+ that.doSearch();
1406
1426
  }
1407
1427
  return;
1408
1428
  }
@@ -1446,7 +1466,7 @@ import DataTable from 'datatables.net';
1446
1466
  that.s.dt.settings()[0].oInit.search["return"]) ||
1447
1467
  code === 13) {
1448
1468
  // Trigger a search
1449
- that.s.dt.draw();
1469
+ that.doSearch();
1450
1470
  }
1451
1471
  // Refocus the element and set the correct cursor position
1452
1472
  if (idx !== null) {
@@ -2374,6 +2394,7 @@ import DataTable from 'datatables.net';
2374
2394
  logicOr: 'Or',
2375
2395
  right: '>',
2376
2396
  rightTitle: 'Indent criteria',
2397
+ search: 'Search',
2377
2398
  title: {
2378
2399
  0: 'Custom Search Builder',
2379
2400
  _: 'Custom Search Builder (%d)'
@@ -2447,7 +2468,12 @@ import DataTable from 'datatables.net';
2447
2468
  .addClass(this.classes.button)
2448
2469
  .attr('type', 'button'),
2449
2470
  logicContainer: $$2('<div/>')
2450
- .addClass(this.classes.logicContainer)
2471
+ .addClass(this.classes.logicContainer),
2472
+ search: $$2('<button/>')
2473
+ .addClass(this.classes.search)
2474
+ .addClass(this.classes.button)
2475
+ .attr('type', 'button')
2476
+ .css('display', 'none')
2451
2477
  };
2452
2478
  // A reference to the top level group is maintained throughout any subgroups and criteria that may be created
2453
2479
  if (this.s.topGroup === undefined) {
@@ -2463,6 +2489,7 @@ import DataTable from 'datatables.net';
2463
2489
  // Turn off listeners
2464
2490
  this.dom.add.off('.dtsb');
2465
2491
  this.dom.logic.off('.dtsb');
2492
+ this.dom.search.off('.dtsb');
2466
2493
  // Trigger event for groups at a higher level to pick up on
2467
2494
  this.dom.container
2468
2495
  .trigger('dtsb-destroy')
@@ -2546,7 +2573,8 @@ import DataTable from 'datatables.net';
2546
2573
  this.dom.container.children().detach();
2547
2574
  this.dom.container
2548
2575
  .append(this.dom.logicContainer)
2549
- .append(this.dom.add);
2576
+ .append(this.dom.add)
2577
+ .append(this.dom.search);
2550
2578
  // Sort the criteria by index so that they appear in the correct order
2551
2579
  this.s.criteria.sort(function (a, b) {
2552
2580
  if (a.criteria.s.index < b.criteria.s.index) {
@@ -2633,10 +2661,14 @@ import DataTable from 'datatables.net';
2633
2661
  // Set criteria left margin
2634
2662
  this.dom.container.css('margin-left', 0);
2635
2663
  }
2664
+ this.dom.search.css('display', 'none');
2636
2665
  return;
2637
2666
  }
2638
2667
  this.dom.clear.height('0px');
2639
2668
  this.dom.logicContainer.append(this.dom.clear);
2669
+ if (!this.s.isChild) {
2670
+ this.dom.search.css('display', 'inline-block');
2671
+ }
2640
2672
  // Prepend logic button
2641
2673
  this.dom.container.prepend(this.dom.logicContainer);
2642
2674
  for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
@@ -2684,6 +2716,9 @@ import DataTable from 'datatables.net';
2684
2716
  _this.s.dt.state.save();
2685
2717
  return false;
2686
2718
  });
2719
+ this.dom.search.on('click.dtsb', function () {
2720
+ _this.s.dt.draw();
2721
+ });
2687
2722
  for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
2688
2723
  var crit = _a[_i];
2689
2724
  crit.criteria.setListeners();
@@ -2699,7 +2734,7 @@ import DataTable from 'datatables.net';
2699
2734
  Group.prototype.addCriteria = function (crit) {
2700
2735
  if (crit === void 0) { crit = null; }
2701
2736
  var index = crit === null ? this.s.criteria.length : crit.s.index;
2702
- var criteria = new Criteria(this.s.dt, this.s.opts, this.s.topGroup, index, this.s.depth, this.s.serverData);
2737
+ var criteria = new Criteria(this.s.dt, this.s.opts, this.s.topGroup, index, this.s.depth, this.s.serverData, this.c.liveSearch);
2703
2738
  // If a Criteria has been passed in then set the values to continue that
2704
2739
  if (crit !== null) {
2705
2740
  criteria.c = crit.c;
@@ -3024,6 +3059,7 @@ import DataTable from 'datatables.net';
3024
3059
  Group.prototype._setup = function () {
3025
3060
  this.setListeners();
3026
3061
  this.dom.add.html(this.s.dt.i18n('searchBuilder.add', this.c.i18n.add));
3062
+ this.dom.search.html(this.s.dt.i18n('searchBuilder.search', this.c.i18n.search));
3027
3063
  this.dom.logic.children().first().html(this.c.logic === 'OR'
3028
3064
  ? this.s.dt.i18n('searchBuilder.logicOr', this.c.i18n.logicOr)
3029
3065
  : this.s.dt.i18n('searchBuilder.logicAnd', this.c.i18n.logicAnd));
@@ -3037,7 +3073,9 @@ import DataTable from 'datatables.net';
3037
3073
  if (this.s.isChild) {
3038
3074
  this.dom.container.append(this.dom.logicContainer);
3039
3075
  }
3040
- this.dom.container.append(this.dom.add);
3076
+ this.dom.container
3077
+ .append(this.dom.add)
3078
+ .append(this.dom.search);
3041
3079
  };
3042
3080
  /**
3043
3081
  * Sets the listener for the logic button
@@ -3077,7 +3115,8 @@ import DataTable from 'datatables.net';
3077
3115
  group: 'dtsb-group',
3078
3116
  inputButton: 'dtsb-iptbtn',
3079
3117
  logic: 'dtsb-logic',
3080
- logicContainer: 'dtsb-logicContainer'
3118
+ logicContainer: 'dtsb-logicContainer',
3119
+ search: 'dtsb-search'
3081
3120
  };
3082
3121
  Group.defaults = {
3083
3122
  columns: true,
@@ -3096,6 +3135,7 @@ import DataTable from 'datatables.net';
3096
3135
  enterSearch: false,
3097
3136
  filterChanged: undefined,
3098
3137
  greyscale: false,
3138
+ liveSearch: true,
3099
3139
  i18n: {
3100
3140
  add: 'Add Condition',
3101
3141
  button: {
@@ -3113,6 +3153,7 @@ import DataTable from 'datatables.net';
3113
3153
  logicOr: 'Or',
3114
3154
  right: '>',
3115
3155
  rightTitle: 'Indent criteria',
3156
+ search: 'Search',
3116
3157
  title: {
3117
3158
  0: 'Custom Search Builder',
3118
3159
  _: 'Custom Search Builder (%d)'
@@ -3531,6 +3572,7 @@ import DataTable from 'datatables.net';
3531
3572
  var count = _this.s.topGroup.count();
3532
3573
  _this._updateTitle(count);
3533
3574
  _this._filterChanged(count);
3575
+ _this._checkClear();
3534
3576
  });
3535
3577
  this.s.dt.on('postEdit.dtsb postCreate.dtsb postRemove.dtsb', function () {
3536
3578
  _this.s.topGroup.redrawContents();
@@ -3554,7 +3596,7 @@ import DataTable from 'datatables.net';
3554
3596
  _this.dom.clearAll.remove();
3555
3597
  });
3556
3598
  };
3557
- SearchBuilder.version = '1.4.2';
3599
+ SearchBuilder.version = '1.6.0';
3558
3600
  SearchBuilder.classes = {
3559
3601
  button: 'dtsb-button',
3560
3602
  clearAll: 'dtsb-clearAll',
@@ -3580,6 +3622,7 @@ import DataTable from 'datatables.net';
3580
3622
  enterSearch: false,
3581
3623
  filterChanged: undefined,
3582
3624
  greyscale: false,
3625
+ liveSearch: true,
3583
3626
  i18n: {
3584
3627
  add: 'Add Condition',
3585
3628
  button: {
@@ -3643,6 +3686,7 @@ import DataTable from 'datatables.net';
3643
3686
  logicOr: 'Or',
3644
3687
  right: '>',
3645
3688
  rightTitle: 'Indent criteria',
3689
+ search: 'Search',
3646
3690
  title: {
3647
3691
  0: 'Custom Search Builder',
3648
3692
  _: 'Custom Search Builder (%d)'
@@ -3660,7 +3704,7 @@ import DataTable from 'datatables.net';
3660
3704
  return SearchBuilder;
3661
3705
  }());
3662
3706
 
3663
- /*! SearchBuilder 1.4.2
3707
+ /*! SearchBuilder 1.6.0
3664
3708
  * ©SpryMedia Ltd - datatables.net/license/mit
3665
3709
  */
3666
3710
  setJQuery($);
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "main": "js/dataTables.searchBuilder.js",
5
5
  "module": "js/dataTables.searchBuilder.mjs",
6
6
  "types": "./types/types.d.ts",
7
- "version": "1.4.2",
7
+ "version": "1.6.0",
8
8
  "files": [
9
9
  "js/**/*.js",
10
10
  "js/**/*.mjs",
@@ -21,7 +21,7 @@
21
21
  "sort"
22
22
  ],
23
23
  "dependencies": {
24
- "datatables.net": ">=1.12.1",
24
+ "datatables.net": ">=1.13.4",
25
25
  "jquery": ">=1.7"
26
26
  },
27
27
  "moduleType": [
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- /*! SearchBuilder 1.4.2
1
+ /*! SearchBuilder 1.5.0
2
2
  * ©SpryMedia Ltd - datatables.net/license/mit
3
3
  */
4
4
  export {};
package/types/types.d.ts CHANGED
@@ -57,7 +57,7 @@ declare module 'datatables.net' {
57
57
  searchBuilder: ApiSearchBuilder<T>;
58
58
  }
59
59
 
60
- interface ApiStatic {
60
+ interface DataTablesStatic {
61
61
  /**
62
62
  * SearchBuilder class
63
63
  */