Forum
00:34
10/08/2009
Hello Tony,
I answered on the question which described problems in the usage of \ (backslash) in the toolbar searching. After I reproduced the problem I found out quickly that it is a bug in jqGrid. To fix the problem I have to make changes in grid.custom.js, grid.base.js, jquery.searchFilter.js and grid.formedit.js files. Here are the list of the changed needed
1) The identical lines 576 and 643 of the file grid.custom.js
should be changed to the following:
(it escapes backslashes and double quotes corresponds to requirement of http://www.json.org/)
2) The line 203 of the file grid.base.js
should be replaced to
(not only double quotes, but also backslashes must be escaped inside of the string used in _toStr)
3) The lines 134 and 136 of the file grid.formedit.js should be appended with additional lines which reset non-multisearch parameters in case of multipleSearch:true and vice versa. The problem exist if one use for example single line searching together with the toolbar filtering having stringResult:true. In the case if one first play with toolbar filtering and then clear all toolbar filters and try to use single line searching. It will follow that only the toolbar filter will be used and the filter from the single line searching will be ignored. So the corresponding code fragment of grid.formedit.js should be
if(p.multipleSearch===false) {
sdata[p.sField] = filters.rules[0].field;
sdata[p.sValue] = filters.rules[0].data;
sdata[p.sOper] = filters.rules[0].op;
sdata[p.sFilter] = "";
} else {
sdata[p.sFilter] = filters;
sdata[p.sField] = sdata[p.sValue] = sdata[p.sOper] = "";
}
grid[0].p.search = hasFilters;
$.extend(grid[0].p.postData,sdata);
Because of the same reason the lines 580 and 647 of the grid.custom.js
should be replaced to
4) In the jquery.searchFilter.js the code fragment
var tField = jQuery(this).find("select[name='field'] :selected").val();
var tOp = jQuery(this).find("select[name='op'] :selected").val();
var tData = jQuery(this).find("input.vdata,select.vdata :selected").val();
tData += "";
tData = tData.replace(/\\/g,'\\\\').replace(/\"/g,'\\"');
if (!opts.stringResult) {
ruleGroup.rules.push({
field: tField,
op: tOp,
data: tData
});
} else {
if (i > 0) ruleGroup += ",";
ruleGroup += "{\"field\":\"" + tField + "\",";
ruleGroup += "\"op\":\"" + tOp + "\",";
ruleGroup += "\"data\":\"" + tData + "\"}";
}
});
should be replaced to
var tField = jQuery(this).find("select[name='field'] :selected").val();
var tOp = jQuery(this).find("select[name='op'] :selected").val();
var tData = jQuery(this).find("input.vdata,select.vdata :selected").val();
tData += "";
if (!opts.stringResult) {
ruleGroup.rules.push({
field: tField,
op: tOp,
data: tData
});
} else {
tData = tData.replace(/\\/g,'\\\\').replace(/\"/g,'\\"');
if (i > 0) ruleGroup += ",";
ruleGroup += "{\"field\":\"" + tField + "\",";
ruleGroup += "\"op\":\"" + tOp + "\",";
ruleGroup += "\"data\":\"" + tData + "\"}";
}
});
because backslashes and double quotes should be escaped only inside of JSON string and not in the object properties.
Best regards
Oleg
14:43
Moderators
30/10/2007
Oleg,
Thanks again. I wil make and test the needed changes.
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.
18:28
10/08/2009
Hello Dinesh,
you will find the modivied developer version of the jqGrid on GitHub and there are not a part of jQuery 3.8.2. The fixes will be first included in the next version of jqGrid.
Best regards
Oleg
21:54
14/02/2011
Hi OlegK,
on [1] you can see, how jquery json plugin escape strings. maybe this will help to escape all special chars.
[1] http://code.google.com/p/jquery-json/source/browse/trunk/jquery.json.js
Cheers 🙂
23:41
10/08/2009
Hi eemie,
it seems to me that no other characters should be escaped. On http://www.json.org you can find the following picture
It means that only '\\' and '"' must be escaped. Some other characters like '/' could be escaped but not must. So one can use for example '/' exactly like '/' in JSON string and the both encoding will be interpret in the same way. So I don't currently see any other characters which can be enter in the search dialog or search toolbar which should be additionally escaped.
It you do find a character or some combination of characters which do must be escaped it would be very interesting.
Best regards
Oleg
Most Users Ever Online: 715
Currently Online:
48 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