jQWidgets Forums

jQuery UI Widgets Forums Grid There is a problem when applyting multiple filters through loop

This topic contains 10 replies, has 3 voices, and was last updated by  robf 5 years ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author

  • sonu
    Participant

    I have store the grid filter into databases and i want to apply all filter using some condition. I have several item in status filtergroup and i have saved filter condition into db. But when i itereate the loop using javascript only one filter is applied in filteritem.

    [
    {
    "repairer_status":{
    "value":"In store awaiting dispatch to repairer, RA provided",
    "condition":"EQUAL",
    "operator":1,
    "type":"stringfilter",
    "id":38
    }
    },
    {
    "repairer_status":{
    "value":"Customer to send to repairer",
    "condition":"EQUAL",
    "operator":1,
    "type":"stringfilter"
    }
    },
    {
    "store":{
    "value":"good",
    "condition":"CONTAINS",
    "operator":1,
    "type":"stringfilter"
    }
    }
    ]

    In the addfilter function.

    var addfilter = function (data) {
       let arr = []
       for (var j = 0; j < data.length; j++) {
         let obj = data[j];
         for (var key in obj) {
           if (obj.hasOwnProperty(key)) {
             var filtergroup = new $.jqx.filter();
    
             let filter_or_operator = obj[key].operator;
             let filtervalue = obj[key].value;
             let filtercondition = obj[key].condition;
    
             let filter = filtergroup.createfilter('stringfilter', filtervalue, filtercondition);
             filtergroup.addfilter(filter_or_operator, filter);
             let keyObj = {}
             keyObj[key] = filtergroup;
             arr.push(keyObj);
             $("#jqxgrid").jqxGrid('addfilter', key, filtergroup);
             
           }
         }
       }
    $("#jqxgrid").jqxGrid('applyfilters');
    })

    In the above loop when i iterate and applied filter so from the above data repairer_status column have two EQUAL filter but it applied only one. so how to apply multiple filter using loop. The key $("#jqxgrid").jqxGrid('addfilter', key, filtergroup) in this is overwrite by last filter but i want all filter should be applied based on config file. please help


    sonu
    Participant

    You can look into this example in fiddle

    In this example i have create a button.on click of this button i have to applied the filter which are setup into newJson variable. so i want to applied those filter on button click.


    sonu
    Participant

    Please check this updated link .


    sonu
    Participant

    Please help me on this .


    sonu
    Participant

    Hey please me on this. can we pass the multiple array in filtergroup.


    Martin
    Participant

    Hello sonu,

    First of all, check your json values. The first filter value for the firstname is “lan” (with small L), instead of “Ian”.
    Also you are declaring the filtergroup inside the for loop, so a new one is created on each iteration and overrides the previous filters.

    I have updated your Example.

    Best Regards,
    Martin

    jQWidgets Team
    http://www.jqwidgets.com/


    sonu
    Participant

    Hi Martin.

    In your example you select the filter Ian and Lars item. But it should be checked in the filteritems but in filteritems all items are unchecked including Ian and Lars and in product also show the Ian which is also wrong. so the result filtered criteria should be same in the filters.


    Martin
    Participant

    Hello sonu,

    I have updated the Example again.

    You need to create a new filtergroup only when you start adding filters for a new key, so that you can you can use the following line:
    $("#jqxgrid").jqxGrid('addfilter', key, filtergroup);, for adding filters to the appropriate column. For that purpose, you need to keep the json data sorted by key, as it is at the moment.

    Best Regards,
    Martin

    jQWidgets Team
    http://www.jqwidgets.com/


    sonu
    Participant

    Thanks Martin.


    robf
    Participant

    Hello,
    Please help me understand how to apply a previously saved filter. I do not understand the example.

    I save a copy of the current filter using ‘getfilterinformation’ and successfully stash the following array:

    {…}]
    0:
    datafield: "currentState"
    displayfield: "currentState"
    filter: i.jqx.filter {operator: "and", evaluate: ƒ, getfilterscount: ƒ, setoperatorsbyfiltertype: ƒ, getoperatorsbyfiltertype: ƒ, …}
    filtercolumn: "currentState"
    filtercolumntext: "Current State"

    1) is there a way to simply apply the whole saved state as the filter? seems you cannot and must iterate.

    So, I get the first value:

    {filter: i.jqx.filter, datafield: "currentState", displayfield: "currentState", filtercolumn: "currentState", filtercolumntext: "Current State"}
    datafield: "currentState"
    displayfield: "currentState"
    filter: i.jqx.filter {operator: "and", evaluate: ƒ, getfilterscount: ƒ, setoperatorsbyfiltertype: ƒ, getoperatorsbyfiltertype: ƒ, …}
    filtercolumn: "currentState"
    filtercolumntext: "Current State"

    It seems that filter is already a filterGroup – i.e. i.jqx.filter and datafield “currentState”

    I try to apply the filter using

    $('#jqxgrid').jqxGrid('addfilter', 'currentState', filtergroup);
    $("#jqxgrid").jqxGrid('applyfilters');

    The filter never gets applied.

    I have looked at the examples and still cannot determine what I am missing.

    Can you please assist.

    Thank you.
    Rob


    robf
    Participant

    Hello,
    Please disregard and mark as closed. It is working as expected by looping through i.jqx.filters
    Thanks.
    Rob

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.