Forum
18:36
13/09/2011
If you have jqGrid default parameters set to Javascript functions, as in:
$.extend($.jgrid.defaults, {
beforeSelectRow: function (id, e) {
alert('hi');
};
});
Then invalid JSON will be generated on jqGridExport if any quotation marks exist in the Javascript. It works fine in IE if you only use single-quotes, but always breaks in Firefox because, for some reason, all single-quotes get interpreted as double-quotes when the property is accessed (I haven't tested in any other browsers yet).
This behavior does NOT occur if you set the grid parameter in the importComplete event of the grid. It only occurs if it has been set using "$.extend($.jgrid.defaults, ...".
Thanks,
Mike
18:40
13/09/2011
I managed to handle this issue by modifying the jqGrid source code, as displayed below, to remove any functions exported with the grid. I will look at submitting this change to the github later, when I have some time to sit down and understand that process.
jqGridExport : function(o) {
o = $.extend({
exptype : "xmlstring",
root: "grid",
ident: "\t"
}, o || {});
var ret = null;
this.each(function () {
if(!this.grid) { return;}
var gprm = $.extend({},$(this).jqGrid("getGridParam"));
// we need to check for:
// 1.multiselect, 2.subgrid 3. treegrid and remove the unneded columns from colNames
if(gprm.rownumbers) {
gprm.colNames.splice(0,1);
gprm.colModel.splice(0,1);
}
if(gprm.multiselect) {
gprm.colNames.splice(0,1);
gprm.colModel.splice(0,1);
}
if(gprm.subGrid) {
gprm.colNames.splice(0,1);
gprm.colModel.splice(0,1);
}
/* BEGIN: Added by Mike Manard, 1/31/2012, to prevent export of invalid JSON */
for (var param in gprm) {
if (typeof (gprm[param]) === 'function') {
delete gprm[param];
}
}
/* END: Added by Mike Manard, 1/31/2012 */
gprm.knv = null;
if(gprm.treeGrid) {
for (var key in gprm.treeReader) {
if(gprm.treeReader.hasOwnProperty(key)) {
gprm.colNames.splice(gprm.colNames.length-1);
gprm.colModel.splice(gprm.colModel.length-1);
}
}
}
switch (o.exptype) {
case 'xmlstring' :
ret = "<"+o.root+">"+xmlJsonClass.json2xml(gprm,o.ident)+"</"+o.root+">";
break;
case 'jsonstring' :
ret = "{"+ xmlJsonClass.toJson(gprm,o.root,o.ident,false)+"}";
if(gprm.postData.filters !== undefined) {
ret=ret.replace(/filters":"/,'filters":');
ret=ret.replace(/}]}"/,'}]}');
}
break;
}
});
return ret;
},
Most Users Ever Online: 715
Currently Online:
33 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