EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: acreonte82 on March 26, 2020, 03:11:42 AM



Title: Datagrid filter new filter operation
Post by: acreonte82 on March 26, 2020, 03:11:42 AM
Hello to all,
i've a need to implement a new filter operation in datagrid.
How I can implement the "IN" operator in filter for text separated by comma?

Ex:
in filter box i write : txt1,tx2
After selected the "IN" operator, i will expect  the 'filterRules' parameter will be formated in this way:

filterRules:  [{"field":"filed_X","op":"in","value":"'txt1','txt2'"}]

Someone can help me?
Thanks


Title: Re: Datagrid filter new filter operation
Post by: jarry on March 26, 2020, 08:24:26 PM
Please extend an 'in' operator.
Code:
$.extend($.fn.datagrid.defaults.operators, {
    in: {
        text: 'In',
        isMatch: function(source, value){
            source = String(source);
            value = String(value);
            var vv = value.split(',');
            for(var i=0; i<vv.length; i++){
                var v = $.trim(vv[i]);
                if (v){
                    var index = source.toLowerCase().indexOf(v.toLowerCase());
                    if (index >= 0){
                        return true;
                    }

                }
            }
            return false;
        }
    }
})

And then apply this 'in' operator to the field using the 'defaultFilterOperator' property.
Code:
dg.datagrid('enableFilter', [{
    field: 'itemid',
    type: 'textbox',
    defaultFilterOperator: 'in'
}])


Title: Re: Datagrid filter new filter operation
Post by: acreonte82 on March 28, 2020, 08:23:31 AM
Thanks!!