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,4 +1,4 @@
1
- /*! SearchBuilder 1.4.2
1
+ /*! SearchBuilder 1.6.0
2
2
  * ©SpryMedia Ltd - datatables.net/license/mit
3
3
  */
4
4
 
@@ -18,7 +18,7 @@
18
18
  }
19
19
  };
20
20
 
21
- if (typeof window !== 'undefined') {
21
+ if (typeof window === 'undefined') {
22
22
  module.exports = function (root, $) {
23
23
  if ( ! root ) {
24
24
  // CommonJS environments without a window global must pass a
@@ -72,11 +72,12 @@ var DataTable = $.fn.dataTable;
72
72
  * The Criteria class is used within SearchBuilder to represent a search criteria
73
73
  */
74
74
  var Criteria = /** @class */ (function () {
75
- function Criteria(table, opts, topGroup, index, depth, serverData) {
75
+ function Criteria(table, opts, topGroup, index, depth, serverData, liveSearch) {
76
76
  var _this = this;
77
77
  if (index === void 0) { index = 0; }
78
78
  if (depth === void 0) { depth = 1; }
79
79
  if (serverData === void 0) { serverData = undefined; }
80
+ if (liveSearch === void 0) { liveSearch = false; }
80
81
  // Check that the required version of DataTables is included
81
82
  if (!dataTable$3 || !dataTable$3.versionCheck || !dataTable$3.versionCheck('1.10.0')) {
82
83
  throw new Error('SearchPane requires DataTables 1.10 or newer');
@@ -96,6 +97,7 @@ var DataTable = $.fn.dataTable;
96
97
  dt: table,
97
98
  filled: false,
98
99
  index: index,
100
+ liveSearch: liveSearch,
99
101
  origData: undefined,
100
102
  preventRedraw: false,
101
103
  serverData: serverData,
@@ -188,6 +190,16 @@ var DataTable = $.fn.dataTable;
188
190
  .replace(/>/g, '>')
189
191
  .replace(/"/g, '"');
190
192
  };
193
+ /**
194
+ * Redraw the DataTable with the current search parameters
195
+ */
196
+ Criteria.prototype.doSearch = function () {
197
+ // Only do the search if live search is disabled, otherwise the search
198
+ // is triggered by the button at the top level group.
199
+ if (this.c.liveSearch) {
200
+ this.s.dt.draw();
201
+ }
202
+ };
191
203
  /**
192
204
  * Parses formatted numbers down to a form where they can be compared
193
205
  *
@@ -411,7 +423,7 @@ var DataTable = $.fn.dataTable;
411
423
  $$3(this).prop('selected', true);
412
424
  data_1.removeClass(italic_1);
413
425
  foundData = true;
414
- dataIdx = $$3(this).val();
426
+ dataIdx = parseInt($$3(this).val(), 10);
415
427
  }
416
428
  else {
417
429
  $$3(this).removeProp('selected');
@@ -493,7 +505,7 @@ var DataTable = $.fn.dataTable;
493
505
  // remove it from the search and trigger a new search
494
506
  if (_this.s.filled) {
495
507
  _this.s.filled = false;
496
- _this.s.dt.draw();
508
+ _this.doSearch();
497
509
  _this.setListeners();
498
510
  }
499
511
  _this.s.dt.state.save();
@@ -534,13 +546,13 @@ var DataTable = $.fn.dataTable;
534
546
  // it from the search and trigger a new search
535
547
  if (_this.s.filled && val !== undefined && _this.dom.inputCont.has(val[0]).length !== 0) {
536
548
  _this.s.filled = false;
537
- _this.s.dt.draw();
549
+ _this.doSearch();
538
550
  _this.setListeners();
539
551
  }
540
552
  }
541
553
  if (_this.dom.value.length === 0 ||
542
554
  _this.dom.value.length === 1 && _this.dom.value[0] === undefined) {
543
- _this.s.dt.draw();
555
+ _this.doSearch();
544
556
  }
545
557
  }
546
558
  else {
@@ -928,7 +940,7 @@ var DataTable = $.fn.dataTable;
928
940
  // If using SSP we want to restrict the amount of server calls that take place
929
941
  // and this will already have taken place
930
942
  if (!this.s.dt.page.info().serverSide) {
931
- this.s.dt.draw();
943
+ this.doSearch();
932
944
  }
933
945
  this.setListeners();
934
946
  }
@@ -1264,13 +1276,15 @@ var DataTable = $.fn.dataTable;
1264
1276
  Criteria.initDate = function (that, fn, preDefined) {
1265
1277
  if (preDefined === void 0) { preDefined = null; }
1266
1278
  var searchDelay = that.s.dt.settings()[0].searchDelay;
1279
+ var i18n = that.s.dt.i18n('datetime', {});
1267
1280
  // Declare date element using DataTables dateTime plugin
1268
1281
  var el = $$3('<input/>')
1269
1282
  .addClass(Criteria.classes.value)
1270
1283
  .addClass(Criteria.classes.input)
1271
1284
  .dtDateTime({
1272
1285
  attachTo: 'input',
1273
- format: that.s.dateFormat ? that.s.dateFormat : undefined
1286
+ format: that.s.dateFormat ? that.s.dateFormat : undefined,
1287
+ i18n: i18n
1274
1288
  })
1275
1289
  .on('change.dtsb', that._throttle(function () {
1276
1290
  return fn(that, this);
@@ -1305,6 +1319,7 @@ var DataTable = $.fn.dataTable;
1305
1319
  var _this = this;
1306
1320
  if (preDefined === void 0) { preDefined = null; }
1307
1321
  var searchDelay = that.s.dt.settings()[0].searchDelay;
1322
+ var i18n = that.s.dt.i18n('datetime', {});
1308
1323
  // Declare all of the date elements that are required using DataTables dateTime plugin
1309
1324
  var els = [
1310
1325
  $$3('<input/>')
@@ -1312,7 +1327,8 @@ var DataTable = $.fn.dataTable;
1312
1327
  .addClass(Criteria.classes.input)
1313
1328
  .dtDateTime({
1314
1329
  attachTo: 'input',
1315
- format: that.s.dateFormat ? that.s.dateFormat : undefined
1330
+ format: that.s.dateFormat ? that.s.dateFormat : undefined,
1331
+ i18n: i18n
1316
1332
  })
1317
1333
  .on('change.dtsb', searchDelay !== null ?
1318
1334
  that.s.dt.settings()[0].oApi._fnThrottle(function () {
@@ -1335,7 +1351,8 @@ var DataTable = $.fn.dataTable;
1335
1351
  .addClass(Criteria.classes.input)
1336
1352
  .dtDateTime({
1337
1353
  attachTo: 'input',
1338
- format: that.s.dateFormat ? that.s.dateFormat : undefined
1354
+ format: that.s.dateFormat ? that.s.dateFormat : undefined,
1355
+ i18n: i18n
1339
1356
  })
1340
1357
  .on('change.dtsb', searchDelay !== null ?
1341
1358
  that.s.dt.settings()[0].oApi._fnThrottle(function () {
@@ -1445,7 +1462,7 @@ var DataTable = $.fn.dataTable;
1445
1462
  !(that.s.dt.settings()[0].oInit.search !== undefined &&
1446
1463
  that.s.dt.settings()[0].oInit.search["return"]) ||
1447
1464
  code === 13) {
1448
- that.s.dt.draw();
1465
+ that.doSearch();
1449
1466
  }
1450
1467
  return;
1451
1468
  }
@@ -1489,7 +1506,7 @@ var DataTable = $.fn.dataTable;
1489
1506
  that.s.dt.settings()[0].oInit.search["return"]) ||
1490
1507
  code === 13) {
1491
1508
  // Trigger a search
1492
- that.s.dt.draw();
1509
+ that.doSearch();
1493
1510
  }
1494
1511
  // Refocus the element and set the correct cursor position
1495
1512
  if (idx !== null) {
@@ -2417,6 +2434,7 @@ var DataTable = $.fn.dataTable;
2417
2434
  logicOr: 'Or',
2418
2435
  right: '>',
2419
2436
  rightTitle: 'Indent criteria',
2437
+ search: 'Search',
2420
2438
  title: {
2421
2439
  0: 'Custom Search Builder',
2422
2440
  _: 'Custom Search Builder (%d)'
@@ -2490,7 +2508,12 @@ var DataTable = $.fn.dataTable;
2490
2508
  .addClass(this.classes.button)
2491
2509
  .attr('type', 'button'),
2492
2510
  logicContainer: $$2('<div/>')
2493
- .addClass(this.classes.logicContainer)
2511
+ .addClass(this.classes.logicContainer),
2512
+ search: $$2('<button/>')
2513
+ .addClass(this.classes.search)
2514
+ .addClass(this.classes.button)
2515
+ .attr('type', 'button')
2516
+ .css('display', 'none')
2494
2517
  };
2495
2518
  // A reference to the top level group is maintained throughout any subgroups and criteria that may be created
2496
2519
  if (this.s.topGroup === undefined) {
@@ -2506,6 +2529,7 @@ var DataTable = $.fn.dataTable;
2506
2529
  // Turn off listeners
2507
2530
  this.dom.add.off('.dtsb');
2508
2531
  this.dom.logic.off('.dtsb');
2532
+ this.dom.search.off('.dtsb');
2509
2533
  // Trigger event for groups at a higher level to pick up on
2510
2534
  this.dom.container
2511
2535
  .trigger('dtsb-destroy')
@@ -2589,7 +2613,8 @@ var DataTable = $.fn.dataTable;
2589
2613
  this.dom.container.children().detach();
2590
2614
  this.dom.container
2591
2615
  .append(this.dom.logicContainer)
2592
- .append(this.dom.add);
2616
+ .append(this.dom.add)
2617
+ .append(this.dom.search);
2593
2618
  // Sort the criteria by index so that they appear in the correct order
2594
2619
  this.s.criteria.sort(function (a, b) {
2595
2620
  if (a.criteria.s.index < b.criteria.s.index) {
@@ -2676,10 +2701,14 @@ var DataTable = $.fn.dataTable;
2676
2701
  // Set criteria left margin
2677
2702
  this.dom.container.css('margin-left', 0);
2678
2703
  }
2704
+ this.dom.search.css('display', 'none');
2679
2705
  return;
2680
2706
  }
2681
2707
  this.dom.clear.height('0px');
2682
2708
  this.dom.logicContainer.append(this.dom.clear);
2709
+ if (!this.s.isChild) {
2710
+ this.dom.search.css('display', 'inline-block');
2711
+ }
2683
2712
  // Prepend logic button
2684
2713
  this.dom.container.prepend(this.dom.logicContainer);
2685
2714
  for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
@@ -2727,6 +2756,9 @@ var DataTable = $.fn.dataTable;
2727
2756
  _this.s.dt.state.save();
2728
2757
  return false;
2729
2758
  });
2759
+ this.dom.search.on('click.dtsb', function () {
2760
+ _this.s.dt.draw();
2761
+ });
2730
2762
  for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) {
2731
2763
  var crit = _a[_i];
2732
2764
  crit.criteria.setListeners();
@@ -2742,7 +2774,7 @@ var DataTable = $.fn.dataTable;
2742
2774
  Group.prototype.addCriteria = function (crit) {
2743
2775
  if (crit === void 0) { crit = null; }
2744
2776
  var index = crit === null ? this.s.criteria.length : crit.s.index;
2745
- var criteria = new Criteria(this.s.dt, this.s.opts, this.s.topGroup, index, this.s.depth, this.s.serverData);
2777
+ var criteria = new Criteria(this.s.dt, this.s.opts, this.s.topGroup, index, this.s.depth, this.s.serverData, this.c.liveSearch);
2746
2778
  // If a Criteria has been passed in then set the values to continue that
2747
2779
  if (crit !== null) {
2748
2780
  criteria.c = crit.c;
@@ -3067,6 +3099,7 @@ var DataTable = $.fn.dataTable;
3067
3099
  Group.prototype._setup = function () {
3068
3100
  this.setListeners();
3069
3101
  this.dom.add.html(this.s.dt.i18n('searchBuilder.add', this.c.i18n.add));
3102
+ this.dom.search.html(this.s.dt.i18n('searchBuilder.search', this.c.i18n.search));
3070
3103
  this.dom.logic.children().first().html(this.c.logic === 'OR'
3071
3104
  ? this.s.dt.i18n('searchBuilder.logicOr', this.c.i18n.logicOr)
3072
3105
  : this.s.dt.i18n('searchBuilder.logicAnd', this.c.i18n.logicAnd));
@@ -3080,7 +3113,9 @@ var DataTable = $.fn.dataTable;
3080
3113
  if (this.s.isChild) {
3081
3114
  this.dom.container.append(this.dom.logicContainer);
3082
3115
  }
3083
- this.dom.container.append(this.dom.add);
3116
+ this.dom.container
3117
+ .append(this.dom.add)
3118
+ .append(this.dom.search);
3084
3119
  };
3085
3120
  /**
3086
3121
  * Sets the listener for the logic button
@@ -3120,7 +3155,8 @@ var DataTable = $.fn.dataTable;
3120
3155
  group: 'dtsb-group',
3121
3156
  inputButton: 'dtsb-iptbtn',
3122
3157
  logic: 'dtsb-logic',
3123
- logicContainer: 'dtsb-logicContainer'
3158
+ logicContainer: 'dtsb-logicContainer',
3159
+ search: 'dtsb-search'
3124
3160
  };
3125
3161
  Group.defaults = {
3126
3162
  columns: true,
@@ -3139,6 +3175,7 @@ var DataTable = $.fn.dataTable;
3139
3175
  enterSearch: false,
3140
3176
  filterChanged: undefined,
3141
3177
  greyscale: false,
3178
+ liveSearch: true,
3142
3179
  i18n: {
3143
3180
  add: 'Add Condition',
3144
3181
  button: {
@@ -3156,6 +3193,7 @@ var DataTable = $.fn.dataTable;
3156
3193
  logicOr: 'Or',
3157
3194
  right: '>',
3158
3195
  rightTitle: 'Indent criteria',
3196
+ search: 'Search',
3159
3197
  title: {
3160
3198
  0: 'Custom Search Builder',
3161
3199
  _: 'Custom Search Builder (%d)'
@@ -3574,6 +3612,7 @@ var DataTable = $.fn.dataTable;
3574
3612
  var count = _this.s.topGroup.count();
3575
3613
  _this._updateTitle(count);
3576
3614
  _this._filterChanged(count);
3615
+ _this._checkClear();
3577
3616
  });
3578
3617
  this.s.dt.on('postEdit.dtsb postCreate.dtsb postRemove.dtsb', function () {
3579
3618
  _this.s.topGroup.redrawContents();
@@ -3597,7 +3636,7 @@ var DataTable = $.fn.dataTable;
3597
3636
  _this.dom.clearAll.remove();
3598
3637
  });
3599
3638
  };
3600
- SearchBuilder.version = '1.4.2';
3639
+ SearchBuilder.version = '1.6.0';
3601
3640
  SearchBuilder.classes = {
3602
3641
  button: 'dtsb-button',
3603
3642
  clearAll: 'dtsb-clearAll',
@@ -3623,6 +3662,7 @@ var DataTable = $.fn.dataTable;
3623
3662
  enterSearch: false,
3624
3663
  filterChanged: undefined,
3625
3664
  greyscale: false,
3665
+ liveSearch: true,
3626
3666
  i18n: {
3627
3667
  add: 'Add Condition',
3628
3668
  button: {
@@ -3686,6 +3726,7 @@ var DataTable = $.fn.dataTable;
3686
3726
  logicOr: 'Or',
3687
3727
  right: '>',
3688
3728
  rightTitle: 'Indent criteria',
3729
+ search: 'Search',
3689
3730
  title: {
3690
3731
  0: 'Custom Search Builder',
3691
3732
  _: 'Custom Search Builder (%d)'
@@ -3703,7 +3744,7 @@ var DataTable = $.fn.dataTable;
3703
3744
  return SearchBuilder;
3704
3745
  }());
3705
3746
 
3706
- /*! SearchBuilder 1.4.2
3747
+ /*! SearchBuilder 1.6.0
3707
3748
  * ©SpryMedia Ltd - datatables.net/license/mit
3708
3749
  */
3709
3750
  setJQuery($);