otsdaq_utilities  v2_05_02_indev
filter.min.js
1 /* Tabulator v4.5.3 (c) Oliver Folkerd */
2 var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Filter=function(e){this.table=e,this.filterList=[],this.headerFilters={},this.headerFilterColumns=[],this.changed=!1};Filter.prototype.initializeColumn=function(e,t){function r(t){var r,o="input"==e.modules.filter.tagType&&"text"==e.modules.filter.attrType||"textarea"==e.modules.filter.tagType?"partial":"match",l="";if(void 0===e.modules.filter.prevSuccess||e.modules.filter.prevSuccess!==t){if(e.modules.filter.prevSuccess=t,e.modules.filter.emptyFunc(t))delete i.headerFilters[n];else{switch(e.modules.filter.value=t,_typeof(e.definition.headerFilterFunc)){case"string":i.filters[e.definition.headerFilterFunc]?(l=e.definition.headerFilterFunc,r=function(r){var n=e.definition.headerFilterFuncParams||{},o=e.getFieldValue(r);return n="function"==typeof n?n(t,o,r):n,i.filters[e.definition.headerFilterFunc](t,o,r,n)}):console.warn("Header Filter Error - Matching filter function not found: ",e.definition.headerFilterFunc);break;case"function":r=function(r){var i=e.definition.headerFilterFuncParams||{},n=e.getFieldValue(r);return i="function"==typeof i?i(t,n,r):i,e.definition.headerFilterFunc(t,n,r,i)},l=r}if(!r)switch(o){case"partial":r=function(r){var i=e.getFieldValue(r);return void 0!==i&&null!==i&&String(i).toLowerCase().indexOf(String(t).toLowerCase())>-1},l="like";break;default:r=function(r){return e.getFieldValue(r)==t},l="="}i.headerFilters[n]={value:t,func:r,type:l}}i.changed=!0,i.table.rowManager.filterRefresh()}return!0}var i=this,n=e.getField();e.modules.filter={success:r,attrType:!1,tagType:!1,emptyFunc:!1},this.generateHeaderFilterElement(e)},Filter.prototype.generateHeaderFilterElement=function(e,t,r){function i(){}var n,o,l,a,s,d,u,f=this,c=this,h=e.modules.filter.success,p=e.getField();if(e.modules.filter.headerElement&&e.modules.filter.headerElement.parentNode&&e.contentElement.removeChild(e.modules.filter.headerElement.parentNode),p){switch(e.modules.filter.emptyFunc=e.definition.headerFilterEmptyCheck||function(e){return!e&&"0"!==e},n=document.createElement("div"),n.classList.add("tabulator-header-filter"),_typeof(e.definition.headerFilter)){case"string":c.table.modules.edit.editors[e.definition.headerFilter]?(o=c.table.modules.edit.editors[e.definition.headerFilter],"tick"!==e.definition.headerFilter&&"tickCross"!==e.definition.headerFilter||e.definition.headerFilterEmptyCheck||(e.modules.filter.emptyFunc=function(e){return!0!==e&&!1!==e})):console.warn("Filter Error - Cannot build header filter, No such editor found: ",e.definition.editor);break;case"function":o=e.definition.headerFilter;break;case"boolean":e.modules.edit&&e.modules.edit.editor?o=e.modules.edit.editor:e.definition.formatter&&c.table.modules.edit.editors[e.definition.formatter]?(o=c.table.modules.edit.editors[e.definition.formatter],"tick"!==e.definition.formatter&&"tickCross"!==e.definition.formatter||e.definition.headerFilterEmptyCheck||(e.modules.filter.emptyFunc=function(e){return!0!==e&&!1!==e})):o=c.table.modules.edit.editors.input}if(o){if(a={getValue:function(){return void 0!==t?t:""},getField:function(){return e.definition.field},getElement:function(){return n},getColumn:function(){return e.getComponent()},getRow:function(){return{normalizeHeight:function(){}}}},u=e.definition.headerFilterParams||{},u="function"==typeof u?u.call(c.table):u,!(l=o.call(this.table.modules.edit,a,function(){},h,i,u)))return void console.warn("Filter Error - Cannot add filter to "+p+" column, editor returned a value of false");if(!(l instanceof Node))return void console.warn("Filter Error - Cannot add filter to "+p+" column, editor should return an instance of Node, the editor returned:",l);p?c.table.modules.localize.bind("headerFilters|columns|"+e.definition.field,function(e){l.setAttribute("placeholder",void 0!==e&&e?e:c.table.modules.localize.getText("headerFilters|default"))}):c.table.modules.localize.bind("headerFilters|default",function(e){l.setAttribute("placeholder",void 0!==c.column.definition.headerFilterPlaceholder&&c.column.definition.headerFilterPlaceholder?c.column.definition.headerFilterPlaceholder:e)}),l.addEventListener("click",function(e){e.stopPropagation(),l.focus()}),l.addEventListener("focus",function(e){var t=f.table.columnManager.element.scrollLeft;t!==f.table.rowManager.element.scrollLeft&&(f.table.rowManager.scrollHorizontal(t),f.table.columnManager.scrollHorizontal(t))}),s=!1,d=function(e){s&&clearTimeout(s),s=setTimeout(function(){h(l.value)},300)},e.modules.filter.headerElement=l,e.modules.filter.attrType=l.hasAttribute("type")?l.getAttribute("type").toLowerCase():"",e.modules.filter.tagType=l.tagName.toLowerCase(),!1!==e.definition.headerFilterLiveFilter&&("autocomplete"!==e.definition.headerFilter&&"tickCross"!==e.definition.headerFilter&&("autocomplete"!==e.definition.editor&&"tickCross"!==e.definition.editor||!0!==e.definition.headerFilter)&&(l.addEventListener("keyup",d),l.addEventListener("search",d),"number"==e.modules.filter.attrType&&l.addEventListener("change",function(e){h(l.value)}),"text"==e.modules.filter.attrType&&"ie"!==this.table.browser&&l.setAttribute("type","search")),"input"!=e.modules.filter.tagType&&"select"!=e.modules.filter.tagType&&"textarea"!=e.modules.filter.tagType||l.addEventListener("mousedown",function(e){e.stopPropagation()})),n.appendChild(l),e.contentElement.appendChild(n),r||c.headerFilterColumns.push(e)}}else console.warn("Filter Error - Cannot add header filter, column has no field set:",e.definition.title)},Filter.prototype.hideHeaderFilterElements=function(){this.headerFilterColumns.forEach(function(e){e.modules.filter&&e.modules.filter.headerElement&&(e.modules.filter.headerElement.style.display="none")})},Filter.prototype.showHeaderFilterElements=function(){this.headerFilterColumns.forEach(function(e){e.modules.filter&&e.modules.filter.headerElement&&(e.modules.filter.headerElement.style.display="")})},Filter.prototype.setHeaderFilterFocus=function(e){e.modules.filter&&e.modules.filter.headerElement?e.modules.filter.headerElement.focus():console.warn("Column Filter Focus Error - No header filter set on column:",e.getField())},Filter.prototype.setHeaderFilterValue=function(e,t){e&&(e.modules.filter&&e.modules.filter.headerElement?(this.generateHeaderFilterElement(e,t,!0),e.modules.filter.success(t)):console.warn("Column Filter Error - No header filter set on column:",e.getField()))},Filter.prototype.reloadHeaderFilter=function(e){e&&(e.modules.filter&&e.modules.filter.headerElement?this.generateHeaderFilterElement(e,e.modules.filter.value,!0):console.warn("Column Filter Error - No header filter set on column:",e.getField()))},Filter.prototype.hasChanged=function(){var e=this.changed;return this.changed=!1,e},Filter.prototype.setFilter=function(e,t,r){var i=this;i.filterList=[],Array.isArray(e)||(e=[{field:e,type:t,value:r}]),i.addFilter(e)},Filter.prototype.addFilter=function(e,t,r){var i=this;Array.isArray(e)||(e=[{field:e,type:t,value:r}]),e.forEach(function(e){(e=i.findFilter(e))&&(i.filterList.push(e),i.changed=!0)}),this.table.options.persistence&&this.table.modExists("persistence",!0)&&this.table.modules.persistence.config.filter&&this.table.modules.persistence.save("filter")},Filter.prototype.findFilter=function(e){var t,r=this;if(Array.isArray(e))return this.findSubFilters(e);var i=!1;return"function"==typeof e.field?i=function(t){return e.field(t,e.type||{})}:r.filters[e.type]?(t=r.table.columnManager.getColumnByField(e.field),i=t?function(i){return r.filters[e.type](e.value,t.getFieldValue(i))}:function(t){return r.filters[e.type](e.value,t[e.field])}):console.warn("Filter Error - No such filter type found, ignoring: ",e.type),e.func=i,!!e.func&&e},Filter.prototype.findSubFilters=function(e){var t=this,r=[];return e.forEach(function(e){(e=t.findFilter(e))&&r.push(e)}),!!r.length&&r},Filter.prototype.getFilters=function(e,t){var r=[];return e&&(r=this.getHeaderFilters()),t&&r.forEach(function(e){"function"==typeof e.type&&(e.type="function")}),r=r.concat(this.filtersToArray(this.filterList,t))},Filter.prototype.filtersToArray=function(e,t){var r=this,i=[];return e.forEach(function(e){var n;Array.isArray(e)?i.push(r.filtersToArray(e,t)):(n={field:e.field,type:e.type,value:e.value},t&&"function"==typeof n.type&&(n.type="function"),i.push(n))}),i},Filter.prototype.getHeaderFilters=function(){var e=[];for(var t in this.headerFilters)e.push({field:t,type:this.headerFilters[t].type,value:this.headerFilters[t].value});return e},Filter.prototype.removeFilter=function(e,t,r){var i=this;Array.isArray(e)||(e=[{field:e,type:t,value:r}]),e.forEach(function(e){var t=-1;t="object"==_typeof(e.field)?i.filterList.findIndex(function(t){return e===t}):i.filterList.findIndex(function(t){return e.field===t.field&&e.type===t.type&&e.value===t.value}),t>-1?(i.filterList.splice(t,1),i.changed=!0):console.warn("Filter Error - No matching filter type found, ignoring: ",e.type)}),this.table.options.persistence&&this.table.modExists("persistence",!0)&&this.table.modules.persistence.config.filter&&this.table.modules.persistence.save("filter")},Filter.prototype.clearFilter=function(e){this.filterList=[],e&&this.clearHeaderFilter(),this.changed=!0,this.table.options.persistence&&this.table.modExists("persistence",!0)&&this.table.modules.persistence.config.filter&&this.table.modules.persistence.save("filter")},Filter.prototype.clearHeaderFilter=function(){var e=this;this.headerFilters={},this.headerFilterColumns.forEach(function(t){t.modules.filter.value=null,t.modules.filter.prevSuccess=void 0,e.reloadHeaderFilter(t)}),this.changed=!0},Filter.prototype.search=function(e,t,r,i){var n=this,o=[],l=[];return Array.isArray(t)||(t=[{field:t,type:r,value:i}]),t.forEach(function(e){(e=n.findFilter(e))&&l.push(e)}),this.table.rowManager.rows.forEach(function(t){var r=!0;l.forEach(function(e){n.filterRecurse(e,t.getData())||(r=!1)}),r&&o.push("data"===e?t.getData("data"):t.getComponent())}),o},Filter.prototype.filter=function(e,t){var r=this,i=[],n=[];return r.table.options.dataFiltering&&r.table.options.dataFiltering.call(r.table,r.getFilters()),r.table.options.ajaxFiltering||!r.filterList.length&&!Object.keys(r.headerFilters).length?i=e.slice(0):e.forEach(function(e){r.filterRow(e)&&i.push(e)}),r.table.options.dataFiltered&&(i.forEach(function(e){n.push(e.getComponent())}),r.table.options.dataFiltered.call(r.table,r.getFilters(),n)),i},Filter.prototype.filterRow=function(e,t){var r=this,i=!0,n=e.getData();r.filterList.forEach(function(e){r.filterRecurse(e,n)||(i=!1)});for(var o in r.headerFilters)r.headerFilters[o].func(n)||(i=!1);return i},Filter.prototype.filterRecurse=function(e,t){var r=this,i=!1;return Array.isArray(e)?e.forEach(function(e){r.filterRecurse(e,t)&&(i=!0)}):i=e.func(t),i},Filter.prototype.filters={"=":function(e,t,r,i){return t==e},"<":function(e,t,r,i){return t<e},"<=":function(e,t,r,i){return t<=e},">":function(e,t,r,i){return t>e},">=":function(e,t,r,i){return t>=e},"!=":function(e,t,r,i){return t!=e},regex:function(e,t,r,i){return"string"==typeof e&&(e=new RegExp(e)),e.test(t)},like:function(e,t,r,i){return null===e||void 0===e?t===e:void 0!==t&&null!==t&&String(t).toLowerCase().indexOf(e.toLowerCase())>-1},in:function(e,t,r,i){return Array.isArray(e)?e.indexOf(t)>-1:(console.warn("Filter Error - filter value is not an array:",e),!1)}},Tabulator.prototype.registerModule("filter",Filter);