EasyUI Forum

General Category => General Discussion => Topic started by: ahybits on December 14, 2015, 05:55:02 PM



Title: Filter with Format and Numbers
Post by: ahybits on December 14, 2015, 05:55:02 PM
Hi

I downloaded the latest filter extension (11/25), but I can seem to get filter to work on a columnt aht has formatted with numbers.  It seems like it only works with text
        field:'completed',
        type:'numberbox',
        options:{precision:2},
        op:['equal','notequal','less','greater']

Thanks


Title: Re: Filter with Format and Numbers
Post by: stworthy on December 14, 2015, 06:31:01 PM
You can override or extend the operators when filtering data, the code below shows how to extend a new operator.
Code:
$.extend($.fn.datagrid.defaults.operators, {
    greater: {
        text: 'Greater',
        isMatch: function(source, value){
            return source > value;
        }
    },
    ngreater: {
        text: 'Greater',
        isMatch: function(source, value){
            return (parseFloat(source)||0) > (parseFloat(value)||0);
        }
    }
})

You also can apply the new operator on the filtering menu.
Code:
op:['equal','notequal','less','ngreater']


Title: Re: Filter with Format and Numbers
Post by: ahybits on December 16, 2015, 08:53:44 AM
Thanks

I tweaked it a bit as my source was <div style="....">100</div>

Code:
        ngreater: {
            text: 'Greater',
            isMatch: function(source, value){
                source = $(source).find("div").html()               
                return (parseFloat(source)||0) > (parseFloat(value)||0);
            }
        }

Thanks