EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: gib65 on March 07, 2017, 11:19:09 AM



Title: help with filtering please
Post by: gib65 on March 07, 2017, 11:19:09 AM
Hello,

I'm experimenting with filtering on the EasyUI datagrid. I want to see if I can do filtering programatically. I managed to get filtering working for 'equals' but not for any other operator. For example, please have a look at the example I'm toying with here:

http://www.shahspace.com/easyui/filtering/datagrid-filter.html

On that page, you will see a grid for which the status has been filtered for 'N'. However, the piece of code doing this filtering is as follows:

dg.datagrid('addFilterRule', {
   field: 'status',
   op: 'notequals',
   value: 'N'
});

Why would it still filter out 'N' even though I'm telling it NOT to filter out 'N'?

Thanks.


Title: Re: help with filtering please
Post by: hatux7 on March 07, 2017, 03:07:01 PM
In the op possible values are: contains,equal,notequal,beginwith,endwith,less,lessorequal,greater,greaterorequal.

So doesn't recognize: 'notequals'.

Take a look: https://jsfiddle.net/hatux7/korr1gxo/ (https://jsfiddle.net/hatux7/korr1gxo/)


Title: Re: help with filtering please
Post by: gib65 on March 08, 2017, 11:19:16 AM
Thanks hatux, but it seems 'notequal' doesn't work either. You can check out the link again to see my changes. You'll see that I also added:

op:['equal','notequal']

...to the status field since every other field had that. It doesn't seem to help though.


Title: Re: help with filtering please
Post by: hatux7 on March 09, 2017, 08:27:23 AM
Hi, i can't see your updates, but i made some changes into the fiddle:

https://jsfiddle.net/hatux7/korr1gxo/2/ (https://jsfiddle.net/hatux7/korr1gxo/2/)

I understand you want the button of options 'equal' and 'notequal'  at the right of the combobox to:

1) Select option from the combobox
2) Click the filter button an select 'nofilter', 'equal' or 'notequal'

Is that what you want?


Title: Re: help with filtering please
Post by: gib65 on March 09, 2017, 09:14:33 AM
I understand you want the button of options 'equal' and 'notequal'  at the right of the combobox to:

1) Select option from the combobox
2) Click the filter button an select 'nofilter', 'equal' or 'notequal'

Is that what you want?

Not exactly. I'm trying to get the status column to filter on 'notequal' to the value 'N' programmatically (i.e. not through the interface).

You may have to clear your cash to see the changes I made at my website. If you open the browser console (what browser are you using?) and look at the source, you should see this:

Code:
$(function(){
var dg = $('#dg').datagrid({
filterBtnIconCls:'icon-filter'
});
dg.datagrid('enableFilter', [{
field:'listprice',
type:'numberbox',
options:{precision:1},
op:['equal','notequal','less','greater']
},{
field:'unitcost',
type:'numberbox',
options:{precision:1},
op:['equal','notequal','less','greater']
},{
field:'status',
type:'combobox',
options:{
panelHeight:'auto',
data:[{value:'',text:'All'},{value:'P',text:'P'},{value:'N',text:'N'}],
onChange:function(value){
if (value == ''){
dg.datagrid('removeFilterRule', 'status');
} else {
dg.datagrid('addFilterRule', {
field: 'status',
op: 'equal',
value: value
});
}
dg.datagrid('doFilter');
}
},
op:['equal','notequal']
}]);


dg.datagrid('addFilterRule', {
field: 'status',
op: 'notequal',
value: 'N'
});
});

It's the part at the end that's not working for me:

dg.datagrid('addFilterRule', {
            field: 'status',
            op: 'notequal',
            value: 'N'
         });

...which should cause the grid to automatically filter out 'N' right after it loads.


Title: Re: help with filtering please
Post by: rezzonico on March 10, 2017, 06:51:22 AM
Select the following link:
https://www.jeasyui.com/extension/datagrid_filter.php

There is the property:
filterRules

Did you tryed it ?


Regards.
Miche


Title: Re: help with filtering please
Post by: gib65 on March 10, 2017, 09:11:40 AM
I figured out what's going on. This is what my code looks like:

Code:
var dg = $('#dg').datagrid({
filterBtnIconCls:'icon-filter'
});
dg.datagrid('enableFilter', [{
field:'listprice',
type:'numberbox',
options:{precision:1},
op:['equal','notequal','less','greater']
},{
field:'unitcost',
type:'numberbox',
options:{precision:1},
op:['equal','notequal','less','greater']
},{
field:'status',
type:'combobox',
options:{
panelHeight:'auto',
data:[{value:'',text:'All'},{value:'P',text:'P'},{value:'N',text:'N'}],
onChange:function(value){
if (value == ''){
dg.datagrid('removeFilterRule', 'status');
} else {
/*dg.datagrid('addFilterRule', {
field: 'status',
op: 'equal',
value: value
});*/
}
dg.datagrid('doFilter');
}
},
op:['equal','notequal']
}]);


dg.datagrid('addFilterRule', {
field: 'status',
op: 'notequal',
value: 'N'
});

It's the last block of code that I'm expecting to filter out 'N':

Code:
dg.datagrid('addFilterRule', {
     field: 'status',
     op: 'notequal',
     value: 'N'
});

...and it does. It's just that this triggers a change, and if you look a few lines above at the onChange event handler in the status column, you see this:

Code:
if (value == ''){
dg.datagrid('removeFilterRule', 'status');
} else {
dg.datagrid('addFilterRule', {
field: 'status',
op: 'equal',
value: value
});
}

value is not '' so it goes into the else and sets the filter operator to 'equal', essentially overriding my 'notequal'.

So I commented that section out and now it works like a charm.