EasyUI Forum
March 29, 2024, 06:35:44 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: help with filtering please  (Read 9202 times)
gib65
Newbie
*
Posts: 29


View Profile Email
« 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.
Logged
hatux7
Newbie
*
Posts: 7


View Profile Email
« Reply #1 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/
Logged
gib65
Newbie
*
Posts: 29


View Profile Email
« Reply #2 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.
Logged
hatux7
Newbie
*
Posts: 7


View Profile Email
« Reply #3 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/

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?
Logged
gib65
Newbie
*
Posts: 29


View Profile Email
« Reply #4 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.
Logged
rezzonico
Full Member
***
Posts: 182


View Profile
« Reply #5 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
Logged
gib65
Newbie
*
Posts: 29


View Profile Email
« Reply #6 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.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!