Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_Related Related Topics sp_TopicIcon
Bug in jqFilter when using multipleGroup
22/05/2011
19:48
Avatar
jayque
Member
Members
Forum Posts: 6
Member Since:
22/05/2011
sp_UserOfflineSmall Offline

Try the following code and apply the template in the search dialog. Result should be the first two entries, instead only the first row is returned.

*edited to include multiline string slashes that had disappeared.

<html>
<head>
    <title>Filter test</title>

    <link rel="stylesheet" type="text/css" media="screen" href="css/ui-lightness/jquery-ui-1.8.13.custom.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />

    <script src="js/jquery-1.5.2.min.js" type="text/javascript"></script>
    <script src="js/jquery-ui-1.8.13.custom.min.js" type="text/javascript"></script>
    <script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
    <script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(function() {
            var template = '{"groupOp": "OR",                           \\
                "rules": [],                                            \\
                "groups": [                                             \\
                    {"groupOp": "AND",                                  \\
                        "rules": [                                      \\
                            {"field": "A", "op": "le", "data": "2"},    \\
                            {"field": "B", "op": "le", "data": "2"}     \\
                        ]                                               \\
                    },                                                  \\
                    {"groupOp": "AND",                                  \\
                        "rules": [                                      \\
                            {"field": "A", "op": "le", "data": "1"},    \\
                            {"field": "B", "op": "le", "data": "1"}     \\
                        ]                                               \\
                    }                                                   \\
                ]                                                       \\
            }'

            $("#list").jqGrid({
                data: [{A: "1",  B: "1", C: "1"}, {A: "2",  B: "2", C: "2"}, {A: "3",  B: "3", C: "3"}],
                datatype: "local",
                colModel: [{name: "A", sorttype: "int"}, {name: "B", sorttype: "int"}, {name: "C", sorttype: "int"}],
                pager: "#pager",
                caption: "Filter test"
            });

            $("#list").jqGrid("navGrid", "#pager",
                {add: false, edit: false, del: false}, {}, {}, {},
                {showQuery: true, multipleGroup: true, multipleSearch: true, tmplNames: ["Template"], tmplFilters: [template]}
            );
        });
    </script>
</head>
<body>
<div>
    <table id="list"></table>
    <div id="pager"></div>
</div>
</body>
</html>

24/05/2011
06:56
Avatar
jayque
Member
Members
Forum Posts: 6
Member Since:
22/05/2011
sp_UserOfflineSmall Offline

Tested and confirmed bug exists in latest commit.

26/05/2011
02:49
Avatar
jayque
Member
Members
Forum Posts: 6
Member Since:
22/05/2011
sp_UserOfflineSmall Offline

Changed from using local to jsonstring to see if that would fix it but still not working.

<html>
<head>
    <title>Filter test</title>

    <link rel="stylesheet" type="text/css" media="screen" href="css/ui-lightness/jquery-ui-1.8.13.custom.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />

    <script src="js/jquery-1.5.2.min.js" type="text/javascript"></script>
    <script src="js/jquery-ui-1.8.13.custom.min.js" type="text/javascript"></script>
    <script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
    <script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(function() {
            // set up grid
            var jsondata = '{                               \\
                "total": "1",                               \\
                "page": "1",                                \\
                "records": "3",                             \\
                "rows": [                                   \\
                    {"id": "1", "cell": ["1", "1", "1"]},   \\
                    {"id": "2", "cell": ["2", "2", "2"]},   \\
                    {"id": "3", "cell": ["3", "3", "3"]}    \\
                ]                                           \\
            }'
            $("#list").jqGrid({
                datastr: jsondata,
                datatype: "jsonstring",
                colModel: [{name: "A", sorttype: "int"}, {name: "B", sorttype: "int"}, {name: "C", sorttype: "int"}],
                pager: "#pager",
                caption: "Filter test"
            });

            // create pager and use a search template
            var template = '{"groupOp": "OR",                           \\
                "rules": [],                                            \\
                "groups": [                                             \\
                    {"groupOp": "AND",                                  \\
                        "rules": [                                      \\
                            {"field": "A", "op": "le", "data": "2"},    \\
                            {"field": "B", "op": "le", "data": "2"}     \\
                        ]                                               \\
                    },                                                  \\
                    {"groupOp": "AND",                                  \\
                        "rules": [                                      \\
                            {"field": "A", "op": "le", "data": "1"},    \\
                            {"field": "B", "op": "le", "data": "1"}     \\
                        ]                                               \\
                    }                                                   \\
                ]                                                       \\
            }'
            $("#list").jqGrid("navGrid", "#pager",
                {add: false, edit: false, del: false}, {}, {}, {},
                {showQuery: true, multipleGroup: true, multipleSearch: true, tmplNames: ["Template"], tmplFilters: [template]}
            );
        });
    </script>
</head>
<body>
    <div>
        <table id="list"></table>
        <div id="pager"></div>
    </div>
</body>
</html>

27/05/2011
18:00
Avatar
jayque
Member
Members
Forum Posts: 6
Member Since:
22/05/2011
sp_UserOfflineSmall Offline

Here is a patch with minimal changes to highlight what needed fixing. Please patch this in the next release as it doesn't work without it.

--- grid.base.js.orig    2011-05-28 00:46:57.711010293 +1000
+++ grid.base.js    2011-05-28 00:50:18.181009036 +1000
@@ -163,6 +163,7 @@
         _stripNum = /[\$,%]/g,
         _lastCommand=null,
         _lastField=null,
+        _orDepth=0,
         _negate=false,
         _queuedOperator="",
         _sorting=[],
@@ -228,12 +229,16 @@
             } else {
                 _query+=_queuedOperator === "" ? " && " :_queuedOperator;
             }
+            for (i=0;i<_orDepth;i++){
+                _query+="(";
+            }
             if(_negate){
                 _query+="!";
             }
             _query+="("+s+")";
             _negate=false;
             _queuedOperator="";
+            _orDepth=0;
         };
         this._setCommand=function(f,c){
             _lastCommand=f;
@@ -444,6 +449,16 @@
             if(f===undefined) { return self; }
             return self._repeatCommand(f,v,x);
         };
+        this.orBegin=function(){
+            _orDepth++;
+            return self;
+        };
+        this.orEnd=function(){
+            if (_query !== null){
+                _query+=")";
+            }
+            return self;
+        };
         this.isNot=function(f){
             _negate=!_negate;
             return self.is(f);
@@ -1433,14 +1448,24 @@
             query = $.jgrid.from(ts.p.data);
             if (ts.p.ignoreCase) { query = query.ignoreCase(); }
             function tojLinq ( group ) {
-                var s = 0, index, opr, rule;
+                var s = 0, index, gor, ror, opr, rule;
                 if (group.groups !== undefined) {
+                    gor = group.groups.length && group.groupOp.toString().toUpperCase() === "OR";
+                    if (gor) {
+                        query.orBegin();
+                    }
                     for (index = 0; index < group.groups.length; index++) {
+                        if (s > 0 && gor) {
+                            query.or();
+                        }
                         try {
                             tojLinq(group.groups[index]);
                         } catch (e) {alert(e);}
                         s++;
                     }
+                    if (gor) {
+                        query.orEnd();
+                    }
                 }
                 if (group.rules !== undefined) {
                     if(s>0) {
@@ -1448,6 +1473,10 @@
                         query = $.jgrid.from( result);
                     }
                     try{
+                        ror = group.rules.length && group.groupOp.toString().toUpperCase() === "OR";
+                        if (ror) {
+                            query.orBegin();
+                        }
                         for (index = 0; index < group.rules.length; index++) {
                             rule = group.rules[index];
                             opr = group.groupOp.toString().toUpperCase();
@@ -1459,6 +1488,9 @@
                             }
                             s++;
                         }
+                        if (ror) {
+                            query.orEnd();
+                        }
                     } catch (g) {alert(g);}
                 }
             }

02/06/2011
20:41
Avatar
A415Hz
Member
Members
Forum Posts: 12
Member Since:
20/10/2010
sp_UserOfflineSmall Offline

Thank you very much, I was able to make multi group search work based on your fix.

I was having trouble doing multiple groups of "OR" that are eventually combined by "AND".

For example "text" "contains" "whatever" AND ("inv_id" "eq" "101" OR "inv_id" "eq" "102" OR "inv_id "eq" "103") would actually work ok in the current version, however things like:

"text" "contains" "whatever" AND ("inv_id" "eq" "101" OR "inv_id" "eq" "102" OR "inv_id "eq" "103") AND ("user_id" "eq" "12" OR "user_id" "eq" "13") didn't work.

So, jayque's patch code addresses this problem, and it's great.

I hope the fix will be applied in the next release.

09/06/2011
22:41
Avatar
A415Hz
Member
Members
Forum Posts: 12
Member Since:
20/10/2010
sp_UserOfflineSmall Offline

Hello,

I have an addition here:

The solution Jayque posted works, except a case where "ignoreCase" being set to true. I needed to add a line of code to include "ignoreCase: true". Here is how.

"Around" line 1450 to 1475 or so, you will add the ignorCase thing.

if (group.rules !== undefined) {

if(s>0) {

var result = query.select();

query = $.jgrid.from(result);

if (ts.p.ignoreCase) { query = query.ignoreCase(); }

}

}

I hope that this minor adjustment will be included in the next release.

20/06/2011
22:46
Avatar
A415Hz
Member
Members
Forum Posts: 12
Member Since:
20/10/2010
sp_UserOfflineSmall Offline

I can confirm that with version 4.1.1 the problem has not been addressed yet. I hope it will be addressed soon. Thank you for all the work.

22/06/2011
16:05
Avatar
jayque
Member
Members
Forum Posts: 6
Member Since:
22/05/2011
sp_UserOfflineSmall Offline

@A415Hz, do you have a test case for the issue you had?

@Tony, I've provided a minimal complete test case and a working patch, is there anything else I need to do to get this fix included?

24/06/2011
12:06
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

@A415Hz

The ignorecase command is started just befoe calling tojLinq function.

As @jayque say could you please post a test case.

Thank you

@jayque,

Thank you very.

Right now I have more time to look into this issue.

You are right, this is a bug.

Your fix seems to be OK.

I have pushed it into the GitHub

https://github.com/tonytomov/jqGrid/commit/25d77bd9e13f16fff0e3ab984702bf323b36b40c

Thanks again

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

24/06/2011
12:50
Avatar
jayque
Member
Members
Forum Posts: 6
Member Since:
22/05/2011
sp_UserOfflineSmall Offline

I couldn't see how ignoreCase wasn't working either without a test case. Any chance of a new 4.1.2 release as for local jqgrid use this is/was a major bug?

Thank you for the excellent grid.

02/07/2011
05:55
Avatar
A415Hz
Member
Members
Forum Posts: 12
Member Since:
20/10/2010
sp_UserOfflineSmall Offline

Hello,

I don't have a test case that I can write here, but yep I was having issues.

However, I tested the latest commit from github and I can confirm that it all works, include ignoreCase issue that I was having.

This is great, and thanks for including the fix. I will look forward to the next release!

03/07/2011
16:35
Avatar
TheCore
Member
Members
Forum Posts: 5
Member Since:
03/07/2011
sp_UserOfflineSmall Offline

Hello,

sorry ... but I still having trouble with the usage of multiple groups in jqgrid. I hope you can help me.

Well, let me explain the situation.

I have to implement a simple booking system. In the backend of this system I use jqGrid to display all reservations, bookings and cancellations in a table. It is possible to cancel a reservation, but not a booking.

The backend user should be able to use 3 filter options stand-alone or in combination:

- Reservations - displays all records, where booking and cancellation is an empty string: (booking = "" AND cancellation = "")

- Bookings - displays all records, where booking is set by timestamp: (booking != "")

- Cancellations - displays all records, where cancellation is set by timestamp: (cancellation != "")

Each of these 3 filter options - seperately performed - works in the expected manner.

But if I try to use the Reservations filter option in an (OR-)relation with the Bookings-filter option  and/or the cancellations-filter option then I always get an empty table instead of my expected data.

So, after a while of intensive testing ... I still don't know, what I am doing wrong ... or ... perhaps ... what the grid is doing wrong ;-).

Thanks in advance for your help and for that fantastic grid!

10/08/2011
19:56
Avatar
A415Hz
Member
Members
Forum Posts: 12
Member Since:
20/10/2010
sp_UserOfflineSmall Offline

A415Hz said:

Hello,

I don't have a test case that I can write here, but yep I was having issues.

However, I tested the latest commit from github and I can confirm that it all works, include ignoreCase issue that I was having.

This is great, and thanks for including the fix. I will look forward to the next release!


I made a new bug report post hee, as I went back and confirmed that ignoreCase still didn't work in 4.1.2:

http://www.trirand.com/blog/?p.....group-bug/

14/08/2011
10:44
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Thanks

See the post on this post

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
23 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information