Author Topic: Filter mode "AND" and "OR" not working at same time  (Read 2970 times)

biswajit

  • Newbie
  • *
  • Posts: 7
    • View Profile
Filter mode "AND" and "OR" not working at same time
« on: October 18, 2016, 01:05:32 pm »
I want the result based on filter mode "OR" according to input in autocomplete i.e in autocomplete if I select Owner= X as well a Manager=Y then grid will show all records for which Owner= X plus all records for which Manager = Y. For example, if there are 2 record for Owner=X and 3 records for Manager=Y then grid will show all 5 records.

Now, If I select Document Type=ABC with above autocomplete input then I want the result where Owner=X and Manager=Y and Document Type=ABC (i.e I want result based on filter mode "AND").

For this situation I write the following code-

                   $( "#grid_documents" ).pqGrid( "option", "filterModel", { on: true, mode : "OR" } );               
                    $("#grid_documents").pqGrid( "filter", {
                        oper: 'add',                       
                        data: [                         
                            { dataIndx: 'Detail', condition: 'range', value: ["X", "Y"]}
                        ]
                    });
                    $("#grid_documents").pqGrid( "filter", {
                        oper: 'add',                       
                        data: [                         
                            { dataIndx: 'Owner', condition: 'range', value: ["X", "Y"]}
                        ]
                    });
                    $("#grid_documents").pqGrid( "filter", {
                        oper: 'add',                       
                        data: [                         
                            { dataIndx: 'Manager', condition: 'range', value: ["X", "Y"]}

                        ]
                    });   

 
               $( "#grid_documents" ).pqGrid( "option", "filterModel", { on: true, mode : "AND" } );                       
                    $("#grid_documents").pqGrid( "filter", {
                        oper: 'add',                     
                        data: [
                            { dataIndx: 'DocType', condition: 'regexp', value: "ABC"}
                        ]
                    });

Here I attached my filter UI, I think it may help to understand the stated problem.

Thank You.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Filter mode "AND" and "OR" not working at same time
« Reply #1 on: October 18, 2016, 06:30:04 pm »
First of all, separate filter functions for different columns ( not good performance wise) can be combined into a single call.

Code: [Select]
$("#grid_documents").pqGrid( "filter", {
                        oper: 'add',                       
                        data: [                         
                            { dataIndx: 'Detail', condition: 'range', value: ["X", "Y"]},
                            { dataIndx: 'Owner', condition: 'range', value: ["X", "Y"]},
                            { dataIndx: 'Manager', condition: 'range', value: ["X", "Y"]}
                        ]
                    });

2. Try this for switching the mode.

 $( "#grid_documents" ).pqGrid( "option", "filterModel.mode", "AND" );     


PS: Your attachment is empty.

biswajit

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Filter mode "AND" and "OR" not working at same time
« Reply #2 on: October 18, 2016, 07:59:05 pm »
Sorry, its not working, the result I got, I am explaining bellow -
Case 1: When I am writing the following code-
                       $( "#grid_documents" ).pqGrid( "option", "filterModel.mode", "OR" );
                       $("#grid_documents").pqGrid( "filter", {
                        oper: 'add',                       
                        data: [                         
                            { dataIndx: 'Detail', condition: 'range', value: ["Tom Brook_52", "Templeton Robinson"]},
                            { dataIndx: 'Owner', condition: 'range', value: ["Tom Brook_52", "Templeton Robinson"]},
                            { dataIndx: 'Manager', condition: 'range', value: ["Tom Brook_52", "Templeton Robinson"]}
                        ]
                    });
           I am getting the result shown in picture "case1".

Cae 2: When I am writing
                      $( "#grid_documents" ).pqGrid( "option", "filterModel.mode", "OR" );
                      $("#grid_documents").pqGrid( "filter", {
                        oper: 'add',                       
                        data: [                         
                            { dataIndx: 'Detail', condition: 'range', value: ["Tom Brook_52", "Templeton Robinson"]},
                            { dataIndx: 'Owner', condition: 'range', value: ["Tom Brook_52", "Templeton Robinson"]},
                            { dataIndx: 'Manager', condition: 'range', value: ["Tom Brook_52", "Templeton Robinson"]}
                        ]
                    });
                    $( "#grid_documents" ).pqGrid( "option", "filterModel.mode", "AND" );
                    $("#grid_documents").pqGrid( "filter", {
                        oper: 'add',                     
                        data: [
                            { dataIndx: 'DocType', condition: 'regexp', value: "Property Image"}
                        ]
                    });
             I am getting the result shown in picture "case2".

My intended result shown in picture "DocumentFilter"
« Last Edit: October 18, 2016, 08:06:32 pm by biswajit »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: Filter mode "AND" and "OR" not working at same time
« Reply #3 on: October 18, 2016, 09:32:21 pm »
When the mode is switched, it is applied to all the columns.

In your case "AND" is applied to all columns, that is why the recordset is empty.

biswajit

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Filter mode "AND" and "OR" not working at same time
« Reply #4 on: October 19, 2016, 12:27:01 pm »
Thank you for your reply.

Is there any way to get my intended result using local filtering?