Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64
Your IP : 18.119.117.122
;(function($){
/*
* jqGrid extension for constructing Grid Data from external file
* Tony Tomov tony@trirand.com
* http://trirand.com/blog/
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
**/
$.fn.extend({
jqGridImport : function(o) {
o = $.extend({
imptype : "xml", // xml, json, xmlstring, jsonstring
impstring: "",
impurl: "",
mtype: "GET",
impData : {},
xmlGrid :{
config : "roots>grid",
data: "roots>rows"
},
jsonGrid :{
config : "grid",
data: "data"
}
}, o || {});
return this.each(function(){
var $t = this;
var XmlConvert = function (xml,o) {
var cnfg = $(o.xmlGrid.config,xml)[0];
var xmldata = $(o.xmlGrid.data,xml)[0];
if(xmlJsonClass.xml2json && $.jgrid.parse) {
var jstr = xmlJsonClass.xml2json(cnfg," ");
var jstr = $.jgrid.parse(jstr);
for(var key in jstr) { var jstr1=jstr[key];}
if(xmldata) {
// save the datatype
var svdatatype = jstr.grid.datatype;
jstr.grid.datatype = 'xmlstring';
jstr.grid.datastr = xml;
$($t).jqGrid( jstr1 ).setGridParam({datatype:svdatatype});
} else {
$($t).jqGrid( jstr1 );
}
jstr = null;jstr1=null;
} else {
alert("xml2json or parse are not present");
}
};
var JsonConvert = function (jsonstr,o){
if (jsonstr && typeof jsonstr == 'string') {
var json = $.jgrid.parse(jsonstr);
var gprm = json[o.jsonGrid.config];
var jdata = json[o.jsonGrid.data];
if(jdata) {
var svdatatype = gprm.datatype;
gprm.datatype = 'jsonstring';
gprm.datastr = jdata;
$($t).jqGrid( gprm ).setGridParam({datatype:svdatatype});
} else {
$($t).jqGrid( gprm );
}
}
};
switch (o.imptype){
case 'xml':
$.ajax({
url:o.impurl,
type:o.mtype,
data: o.impData,
dataType:"xml",
complete: function(xml,stat) {
if(stat == 'success') {
XmlConvert(xml.responseXML,o);
if($.isFunction(o.importComplete)) {
o.importComplete(xml);
}
}
xml=null;
}
});
break;
case 'xmlstring' :
// we need to make just the conversion and use the same code as xml
if(o.impstring && typeof o.impstring == 'string') {
var xmld = $.jgrid.stringToDoc(o.impstring);
if(xmld) {
XmlConvert(xmld,o);
if($.isFunction(o.importComplete)) {
o.importComplete(xmld);
}
o.impstring = null;
}
xmld = null;
}
break;
case 'json':
$.ajax({
url:o.impurl,
type:o.mtype,
data: o.impData,
dataType:"json",
complete: function(json,stat) {
if(stat == 'success') {
JsonConvert(json.responseText,o );
if($.isFunction(o.importComplete)) {
o.importComplete(json);
}
}
json=null;
}
});
break;
case 'jsonstring' :
if(o.impstring && typeof o.impstring == 'string') {
JsonConvert(o.impstring,o );
if($.isFunction(o.importComplete)) {
o.importComplete(o.impstring);
}
o.impstring = null;
}
break;
}
});
},
jqGridExport : function(o) {
o = $.extend({
exptype : "xmlstring",
root: "grid",
ident: "\t"
}, o || {});
var ret = null;
this.each(function () {
if(!this.grid) { return;}
var gprm = $(this).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);
gprm.colModel.splice(0);
}
if(gprm.multiselect) {
gprm.colNames.splice(0);
gprm.colModel.splice(0);
}
if(gprm.subgrid) {
gprm.colNames.splice(0);
gprm.colModel.splice(0);
}
if(gprm.treeGrid) {
for (var key in gprm.treeReader) {
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)+"}";
break;
}
});
return ret;
}
});
})(jQuery);
|