UNPKG

@progress/kendo-ui

Version:

This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.

3 lines (2 loc) 9.97 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("kendo.autocomplete.js"),require("kendo.datepicker.js"),require("kendo.numerictextbox.js"),require("kendo.combobox.js"),require("kendo.dropdownlist.js"),require("kendo.icons.js"),require("kendo.binder.js")):"function"==typeof define&&define.amd?define(["exports","kendo.autocomplete","kendo.datepicker","kendo.numerictextbox","kendo.combobox","kendo.dropdownlist","kendo.icons","kendo.binder"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).kendo=e.kendo||{},e.kendo._globals=e.kendo._globals||{},e.kendo._globals.Filtercell={}))}(this,(function(e){!function(e,t){var r=window.kendo,a=r.ui,o=r.data.DataSource,l=a.Widget,i="change",n="boolean",s="enums",u="string",p="Is equal to",d="Is not equal to",f=["isnull","isnotnull","isempty","isnotempty","isnullorempty","isnotnullorempty"];function c(t){var r="string"==typeof t?t:t.operator;return e.inArray(r,f)>-1}function g(t,r){var a=[];if(e.isPlainObject(t))if(t.hasOwnProperty("filters"))a=t.filters;else if(t.field==r)return t;Array.isArray(t)&&(a=t);for(var o=0;o<a.length;o++){var l=g(a[o],r);if(l)return l}}function h(t,r){t.filters&&(t.filters=e.grep(t.filters,(function(e){return h(e,r),e.filters?e.filters.length:e.field!=r})))}var v=l.extend({init:function(a,o){a=e(a).addClass("k-filtercell");var p,d,f,g,h=this.wrapper=e("<div />").addClass("k-filtercell-wrapper").appendTo(a),v=this,m=o,b=v.operators=o.operators||{},_=v.input=e("<input/>").attr(r.attr("bind"),"value: value").appendTo(h),y=o?o.suggestDataSource:null;y&&(o=e.extend({},o,{suggestDataSource:{}})),l.fn.init.call(v,a[0],o),y&&(v.options.suggestDataSource=y),o=v.options,p=v.dataSource=o.dataSource,v.model=p.reader.model,g=o.type=u;var k=(r.getter("reader.model.fields",!0)(p)||{})[o.field];if(k&&k.type&&(g=o.type=k.type),o.values&&(o.type=g=s),b=b[g]||o.operators[g],!m.operator)for(f in b){o.operator=f;break}if(v._parse=function(e){return null!=e?e+"":e},v.model&&v.model.fields){var w=v.model.fields[o.field];w&&w.parse&&(v._parse=w.parse.bind(w))}v.defaultOperator=o.operator,v.viewModel=d=r.observable({operator:o.operator,value:null,operatorVisible:function(){var e=this.get("value");return null!==e&&e!==t&&"undefined"!=e||c(this.get("operator"))&&v.dataSource.filter()&&!v._clearInProgress}}),v._prevOperator=o.operator,d.bind(i,v.updateDsFilter.bind(v)),g==u&&v.initSuggestDataSource(o),null!==o.inputWidth&&(_.addClass("k-sized-input"),_.width(o.inputWidth)),_.attr("aria-label",v._setInputAriaLabel()),_.attr("title",v._getColumnTitle()),_.attr(r.attr("size"),v.options.size||"medium"),v._setInputType(o,g),g!=n&&!1!==o.showOperators?v._createOperatorDropDown(b):(e('<div unselectable="on" />').css("display","none").text("eq").appendTo(h),h.addClass("k-operator-hidden")),v._createClearIcon(),r.bind(this.wrapper,d),g==u&&(o.template||v.setAutoCompleteSource()),g==s&&v.setComboBoxSource(v.options.values),v._refreshUI(),v._refreshHandler=v._refreshUI.bind(v),v.dataSource.bind(i,v._refreshHandler)},_setInputType:function(t,a){var o=this,l=o.input;if("function"==typeof t.template)t.template.call(o.viewModel,{element:o.input,dataSource:o.suggestDataSource});else if(a==u)l.attr(r.attr("role"),"autocomplete").attr(r.attr("text-field"),t.dataTextField||t.field).attr(r.attr("filter"),t.suggestionOperator).attr(r.attr("delay"),t.delay).attr(r.attr("min-length"),t.minLength).attr(r.attr("value-primitive"),!0);else if("date"==a)l.attr(r.attr("role"),"datepicker").attr("id",r.guid());else if(a==n){l.remove();var i=e("<input type='radio'/>"),p=o.wrapper,d=r.guid(),f=e("<label/>").text(r.htmlEncode(t.messages.isTrue)).append(i);i.attr(r.attr("bind"),"checked:value").attr("name",d).val("true");var c=f.clone().text(r.htmlEncode(t.messages.isFalse));i.clone().val("false").appendTo(c),p.append([f,c])}else"number"==a?l.attr(r.attr("role"),"numerictextbox").attr("title",o._getColumnTitle()):a==s&&l.attr(r.attr("role"),"combobox").attr(r.attr("text-field"),"text").attr(r.attr("suggest"),!0).attr(r.attr("filter"),"contains").attr(r.attr("value-field"),"value").attr(r.attr("value-primitive"),!0)},_getColumnTitle:function(){var e=this.options.column;return e?e.title||e.field:""},_setInputAriaLabel(){return`${this._getColumnTitle()} Filter`},_setOperatorsAriaLabel(){return`Filter cell operator for ${this._getColumnTitle()}`},_createOperatorDropDown:function(t){var a,o=[],l=this.viewModel;for(var i in t)o.push({text:t[i],value:i});this.filterCellOperatorWrapper=e("<div class='k-filtercell-operator'>");var n=e('<input class="k-dropdown-operator" '+r.attr("bind")+'="value: operator"/>');n.attr("aria-label",this._setOperatorsAriaLabel()),n.appendTo(this.filterCellOperatorWrapper),this.filterCellOperatorWrapper.append("&nbsp;"),this.filterCellOperatorWrapper.appendTo(this.wrapper),this.operatorDropDown=n.kendoDropDownList({dataSource:o,size:this.options.size||"medium",dataTextField:"text",dataValueField:"value",open:function(){this.popup.element.width(150)},valuePrimitive:!0}).data("kendoDropDownList"),l.bind("change",(function(){var e=t[l.operator];n.attr("aria-label",e)})),a=this.operatorDropDown.wrapper.attr("aria-label",this._setOperatorsAriaLabel()).find('span[class*="i-caret-alt-down"]'),r.ui.icon(a,{icon:"filter"})},initSuggestDataSource:function(e){var a,l,i,n=e.suggestDataSource;n instanceof o||(!e.customDataSource&&n&&(n.group=t,n.filter=t),n=this.suggestDataSource=o.create(n)),e.customDataSource||(n._pageSize=t,n.reader.data=(a=n.reader.data,l=this.options.field,i=r.getter(l,!0),function(e){for(var t=a(e),r=[],o=0,l={};o<t.length;){var n=t[o++],s=i(n);l.hasOwnProperty(s)||(r.push(n),l[s]=!0)}return r})),this.suggestDataSource=n},setAutoCompleteSource:function(){var e=this.input.data("kendoAutoComplete");e&&e.setDataSource(this.suggestDataSource)},setComboBoxSource:function(e){var t=o.create({data:e}),r=this.input.data("kendoComboBox");r&&!this.options.template&&r.setDataSource(t)},_refreshUI:function(){var t=this,r=g(t.dataSource.filter(),this.options.field)||{},a=t.viewModel;t.manuallyUpdatingVM=!0,r=e.extend(!0,{},r),t.options.type==n&&a.value!==r.value&&t.wrapper.find(":radio").prop("checked",!1),r.operator&&a.set("operator",r.operator),a.set("value",r.value),e.isEmptyObject(r)&&a.trigger(i,{field:"operatorVisible"}),t.manuallyUpdatingVM=!1},_applyFilter:function(e){e.filters.length?this.dataSource.filter(e):this.dataSource.filter({})},updateDsFilter:function(r){var a,o=this,l=o.viewModel;if("operator"==r.field&&l.value===t&&!c(l)&&c(o._prevOperator))return h(a=o.dataSource.filter()||{filters:[],logic:"and"},o.options.field),o._prevOperator=l.operator,void o._applyFilter(a);if(!(o.manuallyUpdatingVM||"operator"==r.field&&l.value===t&&!c(l)||"operator"==r.field&&o._clearInProgress&&null!==l.value)){var n=e.extend({},o.viewModel.toJSON(),{field:o.options.field});o._prevOperator=n.operator;var s={logic:"and",filters:[]},u=!1;if((n.value!==t&&null!==n.value||c(n)&&!this._clearInProgress)&&(s.filters.push(n),u=o.trigger(i,{filter:s,field:o.options.field})),(o._clearInProgress||null===n.value)&&(u=o.trigger(i,{filter:null,field:o.options.field})),!u){var p=o._merge(s);o._applyFilter(p)}}},_merge:function(t){var r,a,o,l=this,i=t.logic||"and",n=t.filters,s=l.dataSource.filter()||{filters:[],logic:"and"};for(h(s,l.options.field),a=0,o=n.length;a<o;a++)(r=n[a]).value=l._parse(r.value);return n=e.grep(n,(function(e){return""!==e.value&&null!==e.value||c(e)})),n.length&&(s.filters.length?(t.filters=n,"and"!==s.logic&&(s.filters=[{logic:s.logic,filters:s.filters}],s.logic="and"),n.length>1?s.filters.push(t):s.filters.push(n[0])):(s.filters=n,s.logic=i)),s},_createClearIcon:function(){var t=this,a=r.getValidCssClass("k-button-","size",this.options.size||"medium"),o=r.htmlEncode(t.options.messages.clear);t.filterCellOperatorWrapper&&t.filterCellOperatorWrapper.length>0||(t.filterCellOperatorWrapper=e("<div class='k-filtercell-operator'>").appendTo(t.wrapper)),e(`<button type='button' class='k-button ${a} k-rounded-md k-button-solid k-button-solid-base k-icon-button' title = '`+o+"'/>").attr("aria-label",o).attr(r.attr("bind"),"visible:operatorVisible").html(r.ui.icon({icon:"filter-clear",iconClass:"k-button-icon"})).on("click",t.clearFilter.bind(t)).appendTo(t.filterCellOperatorWrapper)},clearFilter:function(){this._clearInProgress=!0,c(this.viewModel.operator)&&this.viewModel.set("operator",this.defaultOperator),this.viewModel.set("value",null),this._clearInProgress=!1},destroy:function(){var e=this;e.filterModel=null,e.operatorDropDown=null,e._refreshHandler&&(e.dataSource.bind(i,e._refreshHandler),e._refreshHandler=null),r.unbind(e.element),l.fn.destroy.call(e),r.destroy(e.element)},events:[i],options:{name:"FilterCell",delay:200,minLength:1,inputWidth:null,values:t,customDataSource:!1,field:"",dataTextField:"",type:"string",suggestDataSource:null,suggestionOperator:"startswith",operator:"eq",showOperators:!0,template:null,messages:{isTrue:"is true",isFalse:"is false",filter:"Filter",clear:"Clear",operator:"Operator"},operators:{string:{eq:p,neq:d,startswith:"Starts with",contains:"Contains",doesnotcontain:"Does not contain",endswith:"Ends with",isnull:"Is null",isnotnull:"Is not null",isempty:"Is empty",isnotempty:"Is not empty",isnullorempty:"Has no value",isnotnullorempty:"Has value"},number:{eq:p,neq:d,gte:"Is greater than or equal to",gt:"Is greater than",lte:"Is less than or equal to",lt:"Is less than",isnull:"Is null",isnotnull:"Is not null"},date:{eq:p,neq:d,gte:"Is after or equal to",gt:"Is after",lte:"Is before or equal to",lt:"Is before",isnull:"Is null",isnotnull:"Is not null"},enums:{eq:p,neq:d,isnull:"Is null",isnotnull:"Is not null"}}}});a.plugin(v)}(window.kendo.jQuery);var t=kendo;e.__meta__={id:"filtercell",name:"Row filter",category:"framework",depends:["autocomplete","icons"],advanced:!0},e.default=t,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=kendo.filtercell.min.js.map