From 07ae66a0703ad3deb2744fc03594874575e3e9d6 Mon Sep 17 00:00:00 2001 From: REJack Date: Sun, 19 Sep 2021 12:21:51 +0200 Subject: [PATCH] update plugin files --- .../css/searchBuilder.bootstrap4.css | 5 +- .../css/searchBuilder.bootstrap4.min.css | 2 +- .../js/dataTables.searchBuilder.js | 328 +++++++++++++----- .../js/dataTables.searchBuilder.min.js | 182 +++++----- 4 files changed, 335 insertions(+), 182 deletions(-) diff --git a/plugins/datatables-searchbuilder/css/searchBuilder.bootstrap4.css b/plugins/datatables-searchbuilder/css/searchBuilder.bootstrap4.css index ceabdb9ea..a1d6a52e0 100644 --- a/plugins/datatables-searchbuilder/css/searchBuilder.bootstrap4.css +++ b/plugins/datatables-searchbuilder/css/searchBuilder.bootstrap4.css @@ -1,8 +1,11 @@ div.dt-button-collection { overflow: visible !important; + z-index: 2002 !important; } div.dt-button-collection div.dtsb-searchBuilder { - width: 100% !important; + width: 99% !important; + padding-left: 10px !important; + padding-right: 10px !important; } .dtsb-greyscale { diff --git a/plugins/datatables-searchbuilder/css/searchBuilder.bootstrap4.min.css b/plugins/datatables-searchbuilder/css/searchBuilder.bootstrap4.min.css index 6154c9786..45f27f13b 100644 --- a/plugins/datatables-searchbuilder/css/searchBuilder.bootstrap4.min.css +++ b/plugins/datatables-searchbuilder/css/searchBuilder.bootstrap4.min.css @@ -1 +1 @@ -div.dt-button-collection{overflow:visible !important}div.dt-button-collection div.dtsb-searchBuilder{width:100% !important}.dtsb-greyscale{border:1px solid #cecece !important}div.dtsb-logicContainer .dtsb-greyscale{border:none !important}div.dtsb-searchBuilder{justify-content:space-evenly;cursor:default;margin-bottom:1em;text-align:left}div.dtsb-searchBuilder button.dtsb-button,div.dtsb-searchBuilder select{font-size:1em}div.dtsb-searchBuilder div.dtsb-titleRow{justify-content:space-evenly;margin-bottom:.5em}div.dtsb-searchBuilder div.dtsb-titleRow div.dtsb-title{display:inline-block;padding-top:6px}div.dtsb-searchBuilder div.dtsb-titleRow button.dtsb-clearAll{float:right;margin-bottom:.333em}div.dtsb-searchBuilder div.dtsb-vertical .dtsb-value,div.dtsb-searchBuilder div.dtsb-vertical .dtsb-data,div.dtsb-searchBuilder div.dtsb-vertical .dtsb-condition{display:block}div.dtsb-searchBuilder div.dtsb-group{position:relative;clear:both;margin-bottom:.8em}div.dtsb-searchBuilder div.dtsb-group button.dtsb-clearGroup{margin:2px;text-align:center;padding:0}div.dtsb-searchBuilder div.dtsb-group div.dtsb-logicContainer{-webkit-transform:rotate(90deg);-moz-transform:rotate(90deg);-o-transform:rotate(90deg);-ms-transform:rotate(90deg);transform:rotate(90deg);position:absolute;margin-top:.8em;margin-right:.8em}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria{margin-bottom:.8em}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria select.dtsb-dropDown,div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria input.dtsb-input{padding:.4em;margin-right:.8em;max-width:20em;background-color:rgba(200, 200, 200, 0.3)}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria select.dtsb-dropDown option.dtsb-notItalic,div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria input.dtsb-input option.dtsb-notItalic{font-style:normal}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria select.dtsb-italic{font-style:italic}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria div.dtsb-buttonContainer{float:right;display:inline-block}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria div.dtsb-buttonContainer button.dtsb-delete,div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria div.dtsb-buttonContainer button.dtsb-right,div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria div.dtsb-buttonContainer button.dtsb-left{margin-right:.8em}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria div.dtsb-buttonContainer button.dtsb-delete:last-child,div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria div.dtsb-buttonContainer button.dtsb-right:last-child,div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria div.dtsb-buttonContainer button.dtsb-left:last-child{margin-right:0}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria span.dtsp-joiner{margin-right:.8em}div.dtsb-searchBuilder div.dtsb-titleRow{height:40px}div.dtsb-searchBuilder div.dtsb-titleRow div.dtsb-title{padding-top:10px}div.dtsb-searchBuilder div.dtsb-group button.dtsb-clearGroup{margin-right:8px}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria .form-control{width:auto;display:inline-block}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria select.dtsb-condition{border-color:#28a745}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria select.dtsb-data{border-color:#dc3545}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria select.dtsb-value,div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria input.dtsb-value{border-color:#007bff}div.dtsb-searchBuilder div.dtsb-group div.dtsb-logicContainer{border-radius:4px;display:flex;flex-direction:row;flex-wrap:wrap;justify-content:flex-start;align-content:flex-start;align-items:flex-start;margin-top:10px}div.dtsb-searchBuilder div.dtsb-group div.dtsb-logicContainer button.dtsb-logic{border:none;border-radius:0px;flex-grow:1;flex-shrink:0;flex-basis:3em;margin:0px}div.dtsb-searchBuilder div.dtsb-group div.dtsb-logicContainer button.dtsb-clearGroup{border:none;border-radius:0px;width:2em;margin:0px}div.dt-button-collection div.dtsb-searchBuilder{padding-left:10px;padding-right:10px} +div.dt-button-collection{overflow:visible !important;z-index:2002 !important}div.dt-button-collection div.dtsb-searchBuilder{width:99% !important;padding-left:10px !important;padding-right:10px !important}.dtsb-greyscale{border:1px solid #cecece !important}div.dtsb-logicContainer .dtsb-greyscale{border:none !important}div.dtsb-searchBuilder{justify-content:space-evenly;cursor:default;margin-bottom:1em;text-align:left}div.dtsb-searchBuilder button.dtsb-button,div.dtsb-searchBuilder select{font-size:1em}div.dtsb-searchBuilder div.dtsb-titleRow{justify-content:space-evenly;margin-bottom:.5em}div.dtsb-searchBuilder div.dtsb-titleRow div.dtsb-title{display:inline-block;padding-top:6px}div.dtsb-searchBuilder div.dtsb-titleRow button.dtsb-clearAll{float:right;margin-bottom:.333em}div.dtsb-searchBuilder div.dtsb-vertical .dtsb-value,div.dtsb-searchBuilder div.dtsb-vertical .dtsb-data,div.dtsb-searchBuilder div.dtsb-vertical .dtsb-condition{display:block}div.dtsb-searchBuilder div.dtsb-group{position:relative;clear:both;margin-bottom:.8em}div.dtsb-searchBuilder div.dtsb-group button.dtsb-clearGroup{margin:2px;text-align:center;padding:0}div.dtsb-searchBuilder div.dtsb-group div.dtsb-logicContainer{-webkit-transform:rotate(90deg);-moz-transform:rotate(90deg);-o-transform:rotate(90deg);-ms-transform:rotate(90deg);transform:rotate(90deg);position:absolute;margin-top:.8em;margin-right:.8em}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria{margin-bottom:.8em}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria select.dtsb-dropDown,div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria input.dtsb-input{padding:.4em;margin-right:.8em;max-width:20em;background-color:rgba(200, 200, 200, 0.3)}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria select.dtsb-dropDown option.dtsb-notItalic,div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria input.dtsb-input option.dtsb-notItalic{font-style:normal}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria select.dtsb-italic{font-style:italic}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria div.dtsb-buttonContainer{float:right;display:inline-block}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria div.dtsb-buttonContainer button.dtsb-delete,div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria div.dtsb-buttonContainer button.dtsb-right,div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria div.dtsb-buttonContainer button.dtsb-left{margin-right:.8em}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria div.dtsb-buttonContainer button.dtsb-delete:last-child,div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria div.dtsb-buttonContainer button.dtsb-right:last-child,div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria div.dtsb-buttonContainer button.dtsb-left:last-child{margin-right:0}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria span.dtsp-joiner{margin-right:.8em}div.dtsb-searchBuilder div.dtsb-titleRow{height:40px}div.dtsb-searchBuilder div.dtsb-titleRow div.dtsb-title{padding-top:10px}div.dtsb-searchBuilder div.dtsb-group button.dtsb-clearGroup{margin-right:8px}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria .form-control{width:auto;display:inline-block}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria select.dtsb-condition{border-color:#28a745}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria select.dtsb-data{border-color:#dc3545}div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria select.dtsb-value,div.dtsb-searchBuilder div.dtsb-group div.dtsb-criteria input.dtsb-value{border-color:#007bff}div.dtsb-searchBuilder div.dtsb-group div.dtsb-logicContainer{border-radius:4px;display:flex;flex-direction:row;flex-wrap:wrap;justify-content:flex-start;align-content:flex-start;align-items:flex-start;margin-top:10px}div.dtsb-searchBuilder div.dtsb-group div.dtsb-logicContainer button.dtsb-logic{border:none;border-radius:0px;flex-grow:1;flex-shrink:0;flex-basis:3em;margin:0px}div.dtsb-searchBuilder div.dtsb-group div.dtsb-logicContainer button.dtsb-clearGroup{border:none;border-radius:0px;width:2em;margin:0px}div.dt-button-collection div.dtsb-searchBuilder{padding-left:10px;padding-right:10px} diff --git a/plugins/datatables-searchbuilder/js/dataTables.searchBuilder.js b/plugins/datatables-searchbuilder/js/dataTables.searchBuilder.js index ee7a68e39..dec1837a8 100644 --- a/plugins/datatables-searchbuilder/js/dataTables.searchBuilder.js +++ b/plugins/datatables-searchbuilder/js/dataTables.searchBuilder.js @@ -1,4 +1,4 @@ -/*! SearchBuilder 1.1.0 +/*! SearchBuilder 1.2.1 * ©SpryMedia Ltd - datatables.net/license/mit */ (function () { @@ -239,8 +239,9 @@ /** * Gets the details required to rebuild the criteria */ - Criteria.prototype.getDetails = function () { - var value = this.s.value; + Criteria.prototype.getDetails = function (deFormatDates) { + if (deFormatDates === void 0) { deFormatDates = false; } + this.s.value; // This check is in place for if a custom decimal character is in place if (this.s.type !== null && this.s.type.includes('num') && @@ -258,11 +259,37 @@ this.s.value[i] = splitRD.join('.'); } } + else if (this.s.type !== null && deFormatDates) { + if (this.s.type.includes('date') || + this.s.type.includes('time')) { + for (var i = 0; i < this.s.value.length; i++) { + if (this.s.value[i].match(/^\d{4}-([0]\d|1[0-2])-([0-2]\d|3[01])$/g) === null) { + this.s.value[i] = ''; + } + } + } + else if (this.s.type.includes('moment')) { + for (var i = 0; i < this.s.value.length; i++) { + this.s.value[i] = moment(this.s.value[i], this.s.dateFormat).toISOString(); + } + } + else if (this.s.type.includes('luxon')) { + for (var i = 0; i < this.s.value.length; i++) { + this.s.value[i] = luxon.DateTime.fromFormat(this.s.value[i], this.s.dateFormat).toISO(); + } + } + } + if (this.s.type.includes('num') && this.s.dt.page.info().serverSide) { + for (var i = 0; i < this.s.value.length; i++) { + this.s.value[i] = this.s.value[i].replace(/[^0-9.]/g, ''); + } + } return { condition: this.s.condition, data: this.s.data, origData: this.s.origData, - value: value + type: this.s.type, + value: this.s.value.map(function (a) { return a.toString(); }) }; }; /** @@ -303,11 +330,14 @@ var data_1 = this.dom.data; this.dom.data.children('option').each(function () { if ($$2(this).text() === loadedCriteria.data) { - $$2(this).attr('selected', true); + $$2(this).prop('selected', true); data_1.removeClass(italic_1); foundData = true; dataIdx = $$2(this).val(); } + else { + $$2(this).removeProp('selected'); + } }); } // If the data has been found and selected then the condition can be populated and searched @@ -319,25 +349,40 @@ this.dom.dataTitle.remove(); this._populateCondition(); this.dom.conditionTitle.remove(); - var condition_1; + var condition = void 0; // Check to see if the previously selected condition exists, if so select it - this.dom.condition.children('option').each(function () { + var options = this.dom.condition.children('option'); + // eslint-disable-next-line @typescript-eslint/prefer-for-of + for (var i = 0; i < options.length; i++) { + var option = $$2(options[i]); if (loadedCriteria.condition !== undefined && - $$2(this).val() === loadedCriteria.condition && + option.val() === loadedCriteria.condition && typeof loadedCriteria.condition === 'string') { - $$2(this).attr('selected', true); - condition_1 = $$2(this).val(); + option.prop('selected', true); + condition = option.val(); } - }); - this.s.condition = condition_1; + else { + option.removeProp('selected'); + } + } + this.s.condition = condition; // If the condition has been found and selected then the value can be populated and searched if (this.s.condition !== undefined) { + this.dom.conditionTitle.removeProp('selected'); this.dom.conditionTitle.remove(); this.dom.condition.removeClass(this.classes.italic); + // eslint-disable-next-line @typescript-eslint/prefer-for-of + for (var i = 0; i < options.length; i++) { + var option = $$2(options[i]); + if (option.val() !== this.s.condition) { + option.removeProp('selected'); + } + if (option.prop('selected')) ; + } this._populateValue(loadedCriteria); } else { - this.dom.conditionTitle.prependTo(this.dom.condition).attr('selected', 'true'); + this.dom.conditionTitle.prependTo(this.dom.condition).prop('selected', true); } } }; @@ -349,56 +394,82 @@ this.dom.data .unbind('change') .on('change', function () { - _this.dom.dataTitle.attr('selected', 'false'); - _this.dom.data.removeClass(_this.classes.italic); - _this.s.dataIdx = +_this.dom.data.children('option:selected').val(); - _this.s.data = _this.dom.data.children('option:selected').text(); - _this.s.origData = _this.dom.data.children('option:selected').attr('origData'); - _this.c.orthogonal = _this._getOptions().orthogonal; - // When the data is changed, the values in condition and value may also change so need to renew them - _this._clearCondition(); - _this._clearValue(); - _this._populateCondition(); - // If this criteria was previously active in the search then - // remove it from the search and trigger a new search - if (_this.s.filled) { - _this.s.filled = false; - _this.s.dt.draw(); - _this.setListeners(); + _this.dom.dataTitle.removeProp('selected'); + // Need to go over every option to identify the correct selection + var options = _this.dom.data.children('option.' + _this.classes.option); + // eslint-disable-next-line @typescript-eslint/prefer-for-of + for (var i = 0; i < options.length; i++) { + var option = $$2(options[i]); + if (option.val() === _this.dom.data.val()) { + _this.dom.data.removeClass(_this.classes.italic); + option.prop('selected', true); + _this.s.dataIdx = +option.val(); + _this.s.data = option.text(); + _this.s.origData = option.prop('origData'); + _this.c.orthogonal = _this._getOptions().orthogonal; + // When the data is changed, the values in condition and + // value may also change so need to renew them + _this._clearCondition(); + _this._clearValue(); + _this._populateCondition(); + // If this criteria was previously active in the search then + // remove it from the search and trigger a new search + if (_this.s.filled) { + _this.s.filled = false; + _this.s.dt.draw(); + _this.setListeners(); + } + _this.s.dt.state.save(); + } + else { + option.removeProp('selected'); + } } - _this.s.dt.state.save(); }); this.dom.condition .unbind('change') .on('change', function () { - _this.dom.conditionTitle.attr('selected', 'false'); - _this.dom.condition.removeClass(_this.classes.italic); - var condDisp = _this.dom.condition.children('option:selected').val(); - // Find the condition that has been selected and store it internally - for (var _i = 0, _a = Object.keys(_this.s.conditions); _i < _a.length; _i++) { - var cond = _a[_i]; - if (cond === condDisp) { - _this.s.condition = condDisp; - break; + _this.dom.conditionTitle.removeProp('selected'); + // Need to go over every option to identify the correct selection + var options = _this.dom.condition.children('option.' + _this.classes.option); + // eslint-disable-next-line @typescript-eslint/prefer-for-of + for (var i = 0; i < options.length; i++) { + var option = $$2(options[i]); + if (option.val() === _this.dom.condition.val()) { + _this.dom.condition.removeClass(_this.classes.italic); + option.prop('selected', true); + var condDisp = option.val(); + // Find the condition that has been selected and store it internally + for (var _i = 0, _a = Object.keys(_this.s.conditions); _i < _a.length; _i++) { + var cond = _a[_i]; + if (cond === condDisp) { + _this.s.condition = condDisp; + break; + } + } + // When the condition is changed, the value selector may switch between + // a select element and an input element + _this._clearValue(); + _this._populateValue(); + for (var _b = 0, _c = _this.dom.value; _b < _c.length; _b++) { + var val = _c[_b]; + // If this criteria was previously active in the search then remove + // it from the search and trigger a new search + if (_this.s.filled && val !== undefined && _this.dom.container.has(val[0]).length !== 0) { + _this.s.filled = false; + _this.s.dt.draw(); + _this.setListeners(); + } + } + if (_this.dom.value.length === 0 || + _this.dom.value.length === 1 && _this.dom.value[0] === undefined) { + _this.s.dt.draw(); + } } - } - // When the condition is changed, the value selector may switch between - // a select element and an input element - _this._clearValue(); - _this._populateValue(); - for (var _b = 0, _c = _this.dom.value; _b < _c.length; _b++) { - var val = _c[_b]; - // If this criteria was previously active in the search then remove - // it from the search and trigger a new search - if (_this.s.filled && val !== undefined && _this.dom.container.has(val[0]).length !== 0) { - _this.s.filled = false; - _this.s.dt.draw(); - _this.setListeners(); + else { + option.removeProp('selected'); } } - if (_this.dom.value.length === 0 || _this.dom.value.length === 1 && _this.dom.value[0] === undefined) { - _this.s.dt.draw(); - } }); }; /** @@ -475,7 +546,7 @@ */ Criteria.prototype._clearCondition = function () { this.dom.condition.empty(); - this.dom.conditionTitle.attr('selected', 'true').attr('disabled', 'true'); + this.dom.conditionTitle.prop('selected', true).attr('disabled', 'true'); this.dom.condition.prepend(this.dom.conditionTitle).prop('selectedIndex', 0); this.s.conditions = {}; this.s.condition = undefined; @@ -526,7 +597,7 @@ } // Append the default valueTitle to the default select element this.dom.valueTitle - .attr('selected', 'true'); + .prop('selected', true); this.dom.defaultValue .append(this.dom.valueTitle) .insertAfter(this.dom.condition); @@ -560,10 +631,19 @@ if (conditionsLength === 0) { var column = +this.dom.data.children('option:selected').val(); this.s.type = this.s.dt.columns().type().toArray()[column]; - // If the column type is unknown, call a draw to try reading it again - if (this.s.type === null) { - this.s.dt.draw(false); - this.setListeners(); + var colInits = this.s.dt.settings()[0].aoColumns; + if (colInits !== undefined) { + var colInit = colInits[column]; + if (colInit.searchBuilderType !== undefined && colInit.searchBuilderType !== null) { + this.s.type = colInit.searchBuilderType; + } + else if (this.s.type === undefined || this.s.type === null) { + this.s.type = colInit.sType; + } + } + // If the column type is still unknown, call a draw to try reading it again + if (this.s.type === null || this.s.type === undefined) { + $$2.fn.dataTable.ext.oApi._fnColumnTypes(this.s.dt.settings()[0]); this.s.type = this.s.dt.columns().type().toArray()[column]; } // Enable the condition element @@ -573,7 +653,7 @@ .append(this.dom.conditionTitle) .addClass(this.classes.italic); this.dom.conditionTitle - .attr('selected', 'true'); + .prop('selected', true); var decimal = this.s.dt.settings()[0].oLanguage.sDecimal; // This check is in place for if a custom decimal character is in place if (decimal !== '' && this.s.type.indexOf(decimal) === this.s.type.length - decimal.length) { @@ -640,7 +720,7 @@ .addClass(this.classes.option) .addClass(this.classes.notItalic); if (this.s.condition !== undefined && this.s.condition === condName) { - newOpt.attr('selected', true); + newOpt.prop('selected', true); this.dom.condition.removeClass(this.classes.italic); } conditionOpts.push(newOpt); @@ -694,7 +774,11 @@ }) .addClass(_this.classes.option) .addClass(_this.classes.notItalic) - .attr('origData', col.data)); + .prop('origData', col.data) + .prop('selected', _this.s.dataIdx === opt.index ? true : false)); + if (_this.s.dataIdx === opt.index) { + _this.dom.dataTitle.removeProp('selected'); + } } } }); @@ -717,10 +801,11 @@ }) .addClass(this_1.classes.option) .addClass(this_1.classes.notItalic) - .attr('origData', data.origData); + .prop('origData', data.origData); if (this_1.s.data === data.text) { this_1.s.dataIdx = data.index; - newOpt.attr('selected', true); + this_1.dom.dataTitle.removeProp('selected'); + newOpt.prop('selected', true); this_1.dom.data.removeClass(this_1.classes.italic); } this_1.dom.data.append(newOpt); @@ -926,7 +1011,7 @@ } // If this value was previously selected as indicated by preDefined, then select it again if (preDefined !== null && opt.val() === preDefined[0]) { - opt.attr('selected', true); + opt.prop('selected', true); el.removeClass(Criteria.classes.italic); } } @@ -1007,7 +1092,10 @@ .addClass(Criteria.classes.input) .on('input keypress', that._throttle(function (e) { var code = e.keyCode || e.which; - if (!that.c.enterSearch || code === 13) { + if (!that.c.enterSearch && + !(that.s.dt.settings()[0].oInit.search !== undefined && + that.s.dt.settings()[0].oInit.search["return"]) || + code === 13) { return fn(that, this); } }, searchDelay === null ? 100 : searchDelay)); @@ -1037,7 +1125,10 @@ .addClass(Criteria.classes.input) .on('input keypress', that._throttle(function (e) { var code = e.keyCode || e.which; - if (!that.c.enterSearch || code === 13) { + if (!that.c.enterSearch && + !(that.s.dt.settings()[0].oInit.search !== undefined && + that.s.dt.settings()[0].oInit.search["return"]) || + code === 13) { return fn(that, this); } }, searchDelay === null ? 100 : searchDelay)), @@ -1049,7 +1140,10 @@ .addClass(Criteria.classes.input) .on('input keypress', that._throttle(function (e) { var code = e.keyCode || e.which; - if (!that.c.enterSearch || code === 13) { + if (!that.c.enterSearch && + !(that.s.dt.settings()[0].oInit.search !== undefined && + that.s.dt.settings()[0].oInit.search["return"]) || + code === 13) { return fn(that, this); } }, searchDelay === null ? 100 : searchDelay)) @@ -1086,7 +1180,9 @@ .on('change', that._throttle(function () { return fn(that, this); }, searchDelay === null ? 100 : searchDelay)) - .on('input keypress', that.c.enterSearch ? + .on('input keypress', that.c.enterSearch || + that.s.dt.settings()[0].oInit.search !== undefined && + that.s.dt.settings()[0].oInit.search["return"] ? function (e) { that._throttle(function () { var code = e.keyCode || e.which; @@ -1137,11 +1233,16 @@ function () { fn(that, _this); }) - .on('input keypress', !that.c.enterSearch && searchDelay !== null ? + .on('input keypress', !that.c.enterSearch && + !(that.s.dt.settings()[0].oInit.search !== undefined && + that.s.dt.settings()[0].oInit.search["return"]) && + searchDelay !== null ? that.s.dt.settings()[0].oApi._fnThrottle(function () { return fn(that, this); }, searchDelay) : - that.c.enterSearch ? + that.c.enterSearch || + that.s.dt.settings()[0].oInit.search !== undefined && + that.s.dt.settings()[0].oInit.search["return"] ? function (e) { var code = e.keyCode || e.which; if (code === 13) { @@ -1168,11 +1269,16 @@ function () { fn(that, _this); }) - .on('input keypress', !that.c.enterSearch && searchDelay !== null ? + .on('input keypress', !that.c.enterSearch && + !(that.s.dt.settings()[0].oInit.search !== undefined && + that.s.dt.settings()[0].oInit.search["return"]) && + searchDelay !== null ? that.s.dt.settings()[0].oApi._fnThrottle(function () { return fn(that, this); }, searchDelay) : - that.c.enterSearch ? + that.c.enterSearch || + that.s.dt.settings()[0].oInit.search !== undefined && + that.s.dt.settings()[0].oInit.search["return"] ? function (e) { var code = e.keyCode || e.which; if (code === 13) { @@ -2344,7 +2450,8 @@ */ // Eslint upset at empty object but needs to be done // eslint-disable-next-line @typescript-eslint/ban-types - Group.prototype.getDetails = function () { + Group.prototype.getDetails = function (deFormatDates) { + if (deFormatDates === void 0) { deFormatDates = false; } if (this.s.criteria.length === 0) { return {}; } @@ -2355,7 +2462,7 @@ // NOTE here crit could be either a subgroup or a criteria for (var _i = 0, _a = this.s.criteria; _i < _a.length; _i++) { var crit = _a[_i]; - details.criteria.push(crit.criteria.getDetails()); + details.criteria.push(crit.criteria.getDetails(deFormatDates)); } return details; }; @@ -3031,9 +3138,6 @@ return; } table.settings()[0]._searchBuilder = this; - this.s.dt.one('preXhr', function (e, settings, data) { - data.searchBuilder = _this.c.preDefined !== false ? _this.c.preDefined : null; - }); // Run the remaining setup when the table is initialised if (this.s.dt.settings()[0]._bInitComplete) { this._setUp(); @@ -3050,8 +3154,9 @@ */ // eslint upset at empty object but that is what it is // eslint-disable-next-line @typescript-eslint/ban-types - SearchBuilder.prototype.getDetails = function () { - return this.s.topGroup.getDetails(); + SearchBuilder.prototype.getDetails = function (deFormatDates) { + if (deFormatDates === void 0) { deFormatDates = false; } + return this.s.topGroup.getDetails(deFormatDates); }; /** * Getter for the node of the container for the searchBuilder @@ -3123,10 +3228,17 @@ // eslint-disable-next-line no-extra-parens if (!dataTable.DateTime) { var types = this.s.dt.columns().type().toArray(); + if (types === undefined || types.includes(undefined) || types.includes(null)) { + types = []; + for (var _i = 0, _a = this.s.dt.settings()[0].aoColumns; _i < _a.length; _i++) { + var colInit = _a[_i]; + types.push(colInit.searchBuilderType !== undefined ? colInit.searchBuilderType : colInit.sType); + } + } var columnIdxs = this.s.dt.columns().toArray(); // If the types are not yet set then draw to see if they can be retrieved then - if (types === undefined) { - this.s.dt.draw(false); + if (types === undefined || types.includes(undefined) || types.includes(null)) { + $.fn.dataTable.ext.oApi._fnColumnTypes(this.s.dt.settings()[0]); types = this.s.dt.columns().type().toArray(); } for (var i = 0; i < columnIdxs[0].length; i++) { @@ -3153,6 +3265,11 @@ data.page = _this.s.dt.page(); }); this._build(); + this.s.dt.on('preXhr', function (e, settings, data) { + if (_this.s.dt.page.info().serverSide) { + data.searchBuilder = _this._collapseArray(_this.getDetails(true)); + } + }); if (loadState) { var loadedState = this.s.dt.state.loaded(); // If the loaded State is not null rebuild based on it for statesave @@ -3170,9 +3287,35 @@ } this._setEmptyListener(); this.s.dt.state.save(); - this.s.dt.on('preXhr', function (e, settings, data) { - data.searchBuilder = _this.getDetails(); - }); + }; + SearchBuilder.prototype._collapseArray = function (criteria) { + if (criteria.logic === undefined) { + if (criteria.value !== undefined) { + criteria.value.sort(function (a, b) { + if (!isNaN(+a)) { + a = +a; + b = +b; + } + if (a < b) { + return -1; + } + else if (b < a) { + return 1; + } + else { + return 0; + } + }); + criteria.value1 = criteria.value[0]; + criteria.value2 = criteria.value[1]; + } + } + else { + for (var i = 0; i < criteria.criteria.length; i++) { + criteria.criteria[i] = this._collapseArray(criteria.criteria[i]); + } + } + return criteria; }; /** * Updates the title of the SearchBuilder @@ -3273,6 +3416,7 @@ var count = _this.s.topGroup.count(); _this._updateTitle(count); _this._filterChanged(count); + _this.s.dt.draw(); _this.s.dt.state.save(); }); this.s.topGroup.dom.container.unbind('dtsb-redrawLogic'); @@ -3315,7 +3459,7 @@ _this.dom.clearAll.remove(); }); }; - SearchBuilder.version = '1.1.0'; + SearchBuilder.version = '1.2.1'; SearchBuilder.classes = { button: 'dtsb-button', clearAll: 'dtsb-clearAll', @@ -3415,7 +3559,7 @@ return SearchBuilder; }()); - /*! SearchBuilder 1.1.0 + /*! SearchBuilder 1.2.1 * ©SpryMedia Ltd - datatables.net/license/mit */ // DataTables extensions common UMD. Note that this allows for AMD, CommonJS @@ -3471,7 +3615,6 @@ }; $.fn.dataTable.ext.buttons.searchBuilder = { action: function (e, dt, node, config) { - e.stopPropagation(); this.popover(config._searchBuilder.getNode(), { align: 'dt-container' }); @@ -3492,11 +3635,12 @@ }, text: null }; - apiRegister('searchBuilder.getDetails()', function () { + apiRegister('searchBuilder.getDetails()', function (deFormatDates) { + if (deFormatDates === void 0) { deFormatDates = false; } var ctx = this.context[0]; // If SearchBuilder has not been initialised on this instance then return return ctx._searchBuilder ? - ctx._searchBuilder.getDetails() : + ctx._searchBuilder.getDetails(deFormatDates) : null; }); apiRegister('searchBuilder.rebuild()', function (details) { diff --git a/plugins/datatables-searchbuilder/js/dataTables.searchBuilder.min.js b/plugins/datatables-searchbuilder/js/dataTables.searchBuilder.min.js index 12526d1d3..bc5d8e3f0 100644 --- a/plugins/datatables-searchbuilder/js/dataTables.searchBuilder.min.js +++ b/plugins/datatables-searchbuilder/js/dataTables.searchBuilder.min.js @@ -1,21 +1,21 @@ /*! - SearchBuilder 1.1.0 + SearchBuilder 1.2.1 ©SpryMedia Ltd - datatables.net/license/mit */ var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.SIMPLE_FROUND_POLYFILL=!1;$jscomp.ISOLATE_POLYFILLS=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(k,m,l){if(k==Array.prototype||k==Object.prototype)return k;k[m]=l.value;return k}; $jscomp.getGlobal=function(k){k=["object"==typeof globalThis&&globalThis,k,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var m=0;ml&&(l=Math.max(l+p,0));l=t}},"es6","es3"); +$jscomp.polyfill("Array.prototype.keys",function(k){return k?k:function(){return $jscomp.iteratorFromArray(this,function(m){return m})}},"es6","es3");$jscomp.polyfill("String.prototype.startsWith",function(k){return k?k:function(m,l){var h=$jscomp.checkStringArgs(this,m,"startsWith");m+="";var p=h.length,t=m.length;l=Math.max(0,Math.min(l|0,h.length));for(var v=0;v=t}},"es6","es3"); $jscomp.polyfill("String.prototype.endsWith",function(k){return k?k:function(m,l){var h=$jscomp.checkStringArgs(this,m,"endsWith");m+="";void 0===l&&(l=h.length);l=Math.max(0,Math.min(l|0,h.length));for(var p=m.length;0=p}},"es6","es3"); -(function(){function k(c){h=c;p=c.fn.dataTable}function m(c){B=c;E=c.fn.dataTable}function l(c){x=c;D=c.fn.DataTable}var h,p,t=window.moment,u=window.luxon,q=function(){function c(a,b,d,e,f){var g=this;void 0===e&&(e=0);void 0===f&&(f=1);if(!p||!p.versionCheck||!p.versionCheck("1.10.0"))throw Error("SearchPane requires DataTables 1.10 or newer");this.classes=h.extend(!0,{},c.classes);this.c=h.extend(!0,{},c.defaults,h.fn.dataTable.ext.searchBuilder,b);b=this.c.i18n;this.s={condition:void 0,conditions:{}, +(function(){function k(c){h=c;p=c.fn.dataTable}function m(c){B=c;E=c.fn.dataTable}function l(c){x=c;D=c.fn.DataTable}var h,p,t=window.moment,v=window.luxon,r=function(){function c(a,b,d,e,f){var g=this;void 0===e&&(e=0);void 0===f&&(f=1);if(!p||!p.versionCheck||!p.versionCheck("1.10.0"))throw Error("SearchPane requires DataTables 1.10 or newer");this.classes=h.extend(!0,{},c.classes);this.c=h.extend(!0,{},c.defaults,h.fn.dataTable.ext.searchBuilder,b);b=this.c.i18n;this.s={condition:void 0,conditions:{}, data:void 0,dataIdx:-1,dataPoints:[],dateFormat:!1,depth:f,dt:a,filled:!1,index:e,origData:void 0,topGroup:d,type:"",value:[]};this.dom={buttons:h("
").addClass(this.classes.buttonContainer),condition:h("").addClass(this.classes.data).addClass(this.classes.dropDown).addClass(this.classes.italic),dataTitle:h('