Forum
19:48
22/05/2011
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.
<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>
02:49
22/05/2011
Changed from using local to jsonstring to see if that would fix it but still not working.
<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>
18:00
22/05/2011
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);}
}
}
20:41
20/10/2010
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.
22:41
20/10/2010
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.
12:06
Moderators
30/10/2007
@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.
05:55
20/10/2010
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!
16:35
03/07/2011
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!
19:56
20/10/2010
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:
10:44
Moderators
30/10/2007
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.
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.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66