jQWidgets Forums

jQuery UI Widgets Forums Grid Custom grid filtering

This topic contains 4 replies, has 2 voices, and was last updated by  atomic 3 years, 11 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • Custom grid filtering #120415

    atomic
    Participant

    Hi guys,

    I have one question when applying createfilter and addfilter. I have 3 filter groups on 3 different columns. I defined on each filtergroup operator (or, and).

            //filter colum 1 null values
            var filtergroup1 = new $.jqx.filter();
            filtergroup1.operator = 'or';
            var filtertype1 = 'numericfilter';
            var filter_or_operator1 = 1;
            var filtervalue1 = null;
            var filtercondition1 = 'NOT_NULL';
            var filter1 = filtergroup1.createfilter(filtertype1, filtervalue1, filtercondition1);
            filtergroup1.addfilter(filter_or_operator1, filter1);   
            $.each(years, function (id, year) {
                $divGrid.jqxGrid('addfilter', year, filtergroup1);
            }); 
    
            //filter column 2
            var filtergroup2 = new $.jqx.filter();
            filtergroup2.operator = 'or';
            var filtertype2 = 'stringfilter';
            var filter_or_operator2 = 0;
            var filtervalue2 = 'SC_1';
            var filtercondition2 = 'contains';
            var filter2 = filtergroup2.createfilter(filtertype2, filtervalue2, filtercondition2);
            filtergroup2.addfilter(filter_or_operator2, filter2);    
            $divGrid.jqxGrid('addfilter', 'Sc', filtergroup2);
    
            //filter column 3
            var filtergroup3 = new $.jqx.filter();
            filtergroup3.operator = 'or';
            var filtertype3 = 'stringfilter';
            var filter_or_operator3 = 0;
            var filtervalue3 = 'Tech_1';
            var filtercondition3 = 'contains';
            var filter3 = filtergroup3.createfilter(filtertype3, filtervalue3, filtercondition3);
            filtergroup3.addfilter(filter_or_operator3, filter3);    
            $divGrid.jqxGrid('addfilter', 'Tech', filtergroup3);
    		
    	//apply filters
    	$divGrid.jqxGrid('applyfilters');

    I do not quite understand how to group filtergroup.operator. for example I would like my output to be as
    filtergroup1 or (filtergroup2 and filtergroup3).

    I cannot find a way to group logical operators between columns filter.

    Thanks.

    Custom grid filtering #120426

    Yavor Dashev
    Participant

    Hi atomic,

    If I have understood your use case correctly you will have to define the filtergroup seperately like in your code snippet.
    Also take a look at the following examples:
    https://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/filtering.htm
    https://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/customfiltering.htm

    However you can also share a bit more context of your use case which could help to clarify the situation.

    Please, do not hesitate to contact us if you have any additional questions.

    Best Regards,
    Yavor Dashev
    jQWidgets team
    https://www.jqwidgets.com

    Custom grid filtering #120433

    atomic
    Participant

    Hi Yavor,

    Thanks for your reply. From code above you can see that I created 3 filtergroup. The problem is in filtergroup.operator. I also have declared it 3 times (or, and and). yes you are right in code above it is all set to or, but nevertheless there is no way of chaining them as filtergroup1 or (filtergroup2 and filtergroup3) it can only be filtergroup1 or filtergroup2 and filtergroup3'andlogic operator does not have priority overor` as it should be, so I need bracket which I do not know how to implement.
    I tried all combinations and at the end I managed, if I declare my filtergroup1 after declaring filtergroup2 and filtergroup3.
    I do not know why but it works now.

    Best

    Custom grid filtering #120436

    Yavor Dashev
    Participant

    Hi atomic,

    I was able to exactly reproduce your use case thanks the additional information from you.

    You have defined filtergroup1.operator = 'or'; like so and if you want to have the functionality that you mentioned from your previous reply-filtergroup1 or (filtergroup2 and filtergroup3) you will have to define it like this: filtergroup1.operator = 'and'; or like in your case to define it after filtergroup2 and filtergroup3.

    Hope that my explanation was useful to you.

    Please, do not hesitate to contact us if you have any additional questions.

    Best Regards,
    Yavor Dashev
    jQWidgets team
    https://www.jqwidgets.com

    Custom grid filtering #120437

    atomic
    Participant

    Hi Yavor,

    Thanks. If I define filtergroup1 as filtergroup1.operator = 'and' and also filtergroup2.operator = 'and' and filtergroup3.operator = 'and', then result would be rows if all filter conditions are met. The only way it works, if I define my filter1 as the last one with filtergroup1.operator = 'or' then I think it has priority over last filter operator defined which in this case is filter2 filtergroup2.operator = 'and'.
    Maybe it would be good if you put it in your documentation, so it would be more clear how to chain logical operator on column filters in JQX Grid, or even better to implement priority in logical operators as AND is always enforced first and then OR, which would be more clear.
    Thank you for your help and time.

    Best

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

You must be logged in to reply to this topic.