UNPKG

@progress/kendo-ui

Version:

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

3 lines 10.4 kB
/* @license */ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`kendo.autocomplete.min.js`),require(`kendo.datepicker.min.js`),require(`kendo.numerictextbox.min.js`),require(`kendo.combobox.min.js`),require(`kendo.dropdownlist.min.js`),require(`kendo.icons.min.js`),require(`kendo.binder.min.js`)):typeof define==`function`&&define.amd?define([`exports`,`kendo.autocomplete.min`,`kendo.datepicker.min`,`kendo.numerictextbox.min`,`kendo.combobox.min`,`kendo.dropdownlist.min`,`kendo.icons.min`,`kendo.binder.min`],t):(e=typeof globalThis<`u`?globalThis:e||self,t((e.kendo=e.kendo||{},e.kendo._globals=e.kendo._globals||{},e.kendo._globals.Filtercell={}),e.kendo._globals.Autocomplete,e.kendo._globals.Datepicker,e.kendo._globals.Numerictextbox,e.kendo._globals.Combobox,e.kendo._globals.Dropdownlist,e.kendo._globals.Icons,e.kendo._globals.Binder))})(this,function(e,t,n,r,i,a,o,s){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let c={id:`filtercell`,name:`Row filter`,category:`framework`,depends:[`autocomplete`,`icons`],advanced:!0};(function(e,t){var n=window.kendo,r=n.ui,i=n.data.DataSource,a=r.Widget,o=`change`,s=`boolean`,c=`enums`,l=`string`,u=`Is equal to`,d=`Is not equal to`,f=[`isnull`,`isnotnull`,`isempty`,`isnotempty`,`isnullorempty`,`isnotnullorempty`];function p(t){var n=typeof t==`string`?t:t.operator;return e.inArray(n,f)>-1}function m(t,n){var r=[];if(e.isPlainObject(t)){if(t.hasOwnProperty(`filters`))r=t.filters;else if(t.field==n)return t}Array.isArray(t)&&(r=t);for(var i=0;i<r.length;i++){var a=m(r[i],n);if(a)return a}}function h(t,n){t.filters&&=e.grep(t.filters,function(e){return h(e,n),e.filters?e.filters.length:e.field!=n})}function g(e,t){var r=n.getter(t,!0);return function(t){for(var n=e(t),i=[],a=0,o={};a<n.length;){var s=n[a++],c=r(s);o.hasOwnProperty(c)||(i.push(s),o[c]=!0)}return i}}var _=a.extend({init:function(r,i){r=e(r).addClass(`k-filtercell`);var u=this.wrapper=e(`<div />`).addClass(`k-filtercell-wrapper`).appendTo(r),d=this,f,m,h=i,g,_,v=d.operators=i.operators||{},y=d.input=e(`<input/>`).attr(n.attr(`bind`),`value: value`).appendTo(u),b=i?i.suggestDataSource:null;b&&(i=e.extend({},i,{suggestDataSource:{}})),a.fn.init.call(d,r[0],i),b&&(d.options.suggestDataSource=b),i=d.options,f=d.dataSource=i.dataSource,d.model=f.reader.model,_=i.type=l;var x=(n.getter(`reader.model.fields`,!0)(f)||{})[i.field];if(x&&x.type&&(_=i.type=x.type),i.values&&(i.type=_=c),v=v[_]||i.operators[_],!h.operator)for(g in v){i.operator=g;break}if(d._parse=function(e){return e==null?e:e+``},d.model&&d.model.fields){var S=d.model.fields[i.field];S&&S.parse&&(d._parse=S.parse.bind(S))}d.defaultOperator=i.operator,d.viewModel=m=n.observable({operator:i.operator,value:null,operatorVisible:function(){var e=this.get(`value`);return e!==null&&e!==t&&e!=`undefined`||p(this.get(`operator`))&&d.dataSource.filter()&&!d._clearInProgress}}),d._prevOperator=i.operator,m.bind(o,d.updateDsFilter.bind(d)),_==l&&d.initSuggestDataSource(i),i.inputWidth!==null&&(y.addClass(`k-sized-input`),y.width(i.inputWidth)),y.attr(`aria-label`,d._setInputAriaLabel()),y.attr(`title`,d._getColumnTitle()),y.attr(n.attr(`size`),d.options.size),d._setInputType(i,_),_!=s&&i.showOperators!==!1?d._createOperatorDropDown(v):(e(`<div unselectable="on" />`).css(`display`,`none`).text(`eq`).appendTo(u),u.addClass(`k-operator-hidden`)),d._createClearIcon(),n.bind(this.wrapper,m),_==l&&(i.template||d.setAutoCompleteSource()),_==c&&d.setComboBoxSource(d.options.values),d._refreshUI(),d._refreshHandler=d._refreshUI.bind(d),d.dataSource.bind(o,d._refreshHandler)},_setInputType:function(t,r){var i=this,a=i.input;if(typeof t.template==`function`)t.template.call(i.viewModel,{element:i.input,dataSource:i.suggestDataSource});else if(r==l)a.attr(n.attr(`role`),`autocomplete`).attr(n.attr(`text-field`),t.dataTextField||t.field).attr(n.attr(`filter`),t.suggestionOperator).attr(n.attr(`delay`),t.delay).attr(n.attr(`min-length`),t.minLength).attr(n.attr(`value-primitive`),!0);else if(r==`date`)a.attr(n.attr(`role`),`datepicker`).attr(`id`,n.guid());else if(r==s){a.remove();var o=e(`<input type='radio'/>`),u=i.wrapper,d=n.guid(),f=e(`<label/>`).text(n.htmlEncode(t.messages.isTrue)).append(o);o.attr(n.attr(`bind`),`checked:value`).attr(`name`,d).val(`true`);var p=f.clone().text(n.htmlEncode(t.messages.isFalse));o.clone().val(`false`).appendTo(p),u.append([f,p])}else r==`number`?a.attr(n.attr(`role`),`numerictextbox`).attr(`title`,i._getColumnTitle()):r==c&&a.attr(n.attr(`role`),`combobox`).attr(n.attr(`text-field`),`text`).attr(n.attr(`suggest`),!0).attr(n.attr(`filter`),`contains`).attr(n.attr(`value-field`),`value`).attr(n.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 r=[],i=this.viewModel,a;for(var o in t)r.push({text:t[o],value:o});this.filterCellOperatorWrapper=e(`<div class='k-filtercell-operator'>`);var s=e(`<input class="k-dropdown-operator" `+n.attr(`bind`)+`="value: operator"/>`);s.attr(`aria-label`,this._setOperatorsAriaLabel()),s.appendTo(this.filterCellOperatorWrapper),this.filterCellOperatorWrapper.append(`&nbsp;`),this.filterCellOperatorWrapper.appendTo(this.wrapper),this.operatorDropDown=s.kendoDropDownList({dataSource:r,size:this.options.size,dataTextField:`text`,dataValueField:`value`,adaptiveMode:this.options.adaptiveMode,open:function(){(this.options.adaptiveMode==`auto`&&this.largeMQL.mediaQueryList.matches||this.options.adaptiveMode==`none`)&&this.popup.element.width(150)},valuePrimitive:!0}).data(`kendoDropDownList`),i.bind(`change`,function(){var e=t[i.operator];s.attr(`aria-label`,e)}),a=this.operatorDropDown.wrapper.attr(`aria-label`,this._setOperatorsAriaLabel()).find(`span[class*="i-caret-alt-down"]`),n.ui.icon(a,{icon:`filter`})},initSuggestDataSource:function(e){var n=e.suggestDataSource;n instanceof i||(!e.customDataSource&&n&&(n.group=t,n.filter=t),n=this.suggestDataSource=i.create(n)),e.customDataSource||(n._pageSize=t,n.reader.data=g(n.reader.data,this.options.field)),this.suggestDataSource=n},setAutoCompleteSource:function(){var e=this.input.data(`kendoAutoComplete`);e&&e.setDataSource(this.suggestDataSource)},setComboBoxSource:function(e){var t=i.create({data:e}),n=this.input.data(`kendoComboBox`);n&&!this.options.template&&n.setDataSource(t)},_refreshUI:function(){var t=this,n=m(t.dataSource.filter(),this.options.field)||{},r=t.viewModel;t.manuallyUpdatingVM=!0,n=e.extend(!0,{},n),t.options.type==s&&r.value!==n.value&&t.wrapper.find(`:radio`).prop(`checked`,!1),n.operator&&r.set(`operator`,n.operator),r.set(`value`,n.value),e.isEmptyObject(n)&&r.trigger(o,{field:`operatorVisible`}),t.manuallyUpdatingVM=!1},_applyFilter:function(e){e.filters.length?this.dataSource.filter(e):this.dataSource.filter({})},updateDsFilter:function(n){var r=this,i=r.viewModel,a;if(n.field==`operator`&&i.value===t&&!p(i)&&p(r._prevOperator)){a=r.dataSource.filter()||{filters:[],logic:`and`},h(a,r.options.field),r._prevOperator=i.operator,r._applyFilter(a);return}if(!(r.manuallyUpdatingVM||n.field==`operator`&&i.value===t&&!p(i)||n.field==`operator`&&r._clearInProgress&&i.value!==null)){var s=e.extend({},r.viewModel.toJSON(),{field:r.options.field});r._prevOperator=s.operator;var c={logic:`and`,filters:[]},l=!1;if((s.value!==t&&s.value!==null||p(s)&&!this._clearInProgress)&&(c.filters.push(s),l=r.trigger(o,{filter:c,field:r.options.field})),(r._clearInProgress||s.value===null)&&(l=r.trigger(o,{filter:null,field:r.options.field})),!l){var u=r._merge(c);r._applyFilter(u)}}},_merge:function(t){var n=this,r=t.logic||`and`,i=t.filters,a,o=n.dataSource.filter()||{filters:[],logic:`and`},s,c;for(h(o,n.options.field),s=0,c=i.length;s<c;s++)a=i[s],a.value=n._parse(a.value);return i=e.grep(i,function(e){return e.value!==``&&e.value!==null||p(e)}),i.length&&(o.filters.length?(t.filters=i,o.logic!==`and`&&(o.filters=[{logic:o.logic,filters:o.filters}],o.logic=`and`),i.length>1?o.filters.push(t):o.filters.push(i[0])):(o.filters=i,o.logic=r)),o},_createClearIcon:function(){var t=this,r=n.getValidCssClass(`k-button-`,`size`,this.options.size),i=n.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 ${r} k-icon-button' title = '`+i+`'/>`).attr(`aria-label`,i).attr(n.attr(`bind`),`visible:operatorVisible`).html(n.ui.icon({icon:`filter-clear`,iconClass:`k-button-icon`})).on(`click`,t.clearFilter.bind(t)).appendTo(t.filterCellOperatorWrapper)},clearFilter:function(){this._clearInProgress=!0,p(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(o,e._refreshHandler),null),n.unbind(e.element),a.fn.destroy.call(e),n.destroy(e.element)},events:[o],options:{name:`FilterCell`,adaptiveMode:`none`,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:u,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:u,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:u,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:u,neq:d,isnull:`Is null`,isnotnull:`Is not null`}}}});r.plugin(_)})(window.kendo.jQuery);var l=kendo;e.__meta__=c,e.default=l}); //# sourceMappingURL=kendo.filtercell.min.js.map