Forum


08:49

03/03/2009

Hi there. New user here trying to get some reasonably complex JSON to work with JQueryGrid. First off, thanks to the devlopers for putting the immense effort into this. It's a sweet product and I hope we can make it work for this project!
Anyway, the JSON is converted from a Google Search Appliance XML. The 'root' is nested and the 'cells' are likewise deeply nested. I'm wondering if someone can take a peek at my n00b code and let me know what syntax should be used; everything I've tried so far does not work (nothing is displayed + no errors) - it's probably something I'm doing ...
Thanks is advance! -bill
jQuery("#list").jqGrid({ url:'http://dev/tools/google/tests/.....m',
datatype: 'json',
mtype: 'POST',
colNames:['CorpID','Title'],
colModel :[
{name:'MT[1].V', index:'corpid', width:100},
{name:'S', index:'title', width:300}
],
width: 800,
pager: jQuery('#pager'),
rowNum:10,
rowList:[10,20,30],
sortname: 'corpid',
sortorder: "desc",
viewrecords: true,
imgpath: '../jquery/jgrid/themes/basic/images',
caption: 'Can we display complex JSON?',
jsonReader:{
root: "R",
page: "SN",
total: "M",
records: "EN",
cell: "MT",
repeatitems: false,
id: "N"
}
});
});
'GSP' is the top-level element (or document root). 'RES.EN' maps to records. 'R' is the root, and 'MT' are cells. Note that each MT has an N and V element for Name/Value, respectively. I pretty much need to access most of the elements, regardless of their position.
{
"GSP": {
"RES": {
"EN": 100,
"R": [
{
"FS": {
"NAME": "date",
"VALUE": "2001-12-01"
},
"U": "http://sever/apps/google/DS/DocViewer.cfm?system=foo&mimetype
=application/msword&document_id=1C814F68-9E1E-42C7-B0C0-AD27867844B5.doc",
"HAS": {
"C": {
"SZ": "",
"ENC": "UTF-8",
"CID": "vsTGEGvGa7MJ"
},
"L": {}
},
"T": "<b>Corp</b> Docket No",
"S": "<b>Corp</b> Docket No.: asdasd. October 12, 2001. John Q Public, President
. Company<br> Foo Company, LLC. 100 Main Avenue. NY, New York 12345. <b>...</b>"
,
"N": 1,
"UE": "http://server/apps/google/DS/DocViewer.cfm%3Fsystem%3Dfoo%26mimetype
%3Dapplication/msword%26document_id%3D1C814F68-9E1E-42C7-B0C0-AD27867844B5.doc",
"MIME": "application/msword",
"LANG": "en",
"MT": [
{
"V": 0,
"N": "MehId"
},
{
"V": 12345,
"N": "CorpId"
},
{
"V": 0,
"N": "BahType"
},
{
"V": "application/msword",
"N": "MimeType"
},
{
"V": "2001-12-01",
"N": "DocDate"
},
{
"V": "Some Data",
"N": "title"
},
{
"V": 12344,
"N": "Document_Id"
},
{
"V": "Corp Name Office.doc",
"N": "filename"
},
{
"V": "John Q Public",
"N": "contact"
},
{
"V": "Corp, LLC",
"N": "organizationName"
},
{
"V": 123,
"N": "Region"
},
{
"V": "http://server/apps/google/DS/DocViewer.cfm?system=foo
&mimetype=application/msword&document_id=1C814F68-9E1E-42C7-B0C0-AD27867844B5.doc",
"N": "URL"
},
{
"V": "Foo",
"N": "system"
},
{
"V": "South Pole REGION",
"N": "Author"
},
{
"V": "South Pole REGION",
"N": "last saved by"
},
{
"V": 4,
"N": "revision number"
},
{
"V": "Corp
"N": "company"
}
],
"RK": 10
}
]
},
"PARAM": [
{
"name": "entqr",
"value": 0,
"original_value": 0
},
{
"name": "access",
"value": "p",
"original_value": "p"
},
{
"name": "getfields",
"value": "*",
"original_value": "*"
},
{
"name": "start",
"value": 0,
"original_value": 0
},
{
"name": "sort",
"value": "date:D:L:d1",
"original_value": "date%3AD%3AL%3Ad1"
},
{
"name": "output",
"value": "xml",
"original_value": "xml"
},
{
"name": "ie",
"value": "UTF-8",
"original_value": "UTF-8"
},
{
"name": "client",
"value": "default_frontend",
"original_value": "default_frontend"
},
{
"name": "q",
"value": "test",
"original_value": "ots"
},
{
"name": "requiredfields",
"value": "",
"original_value": ""
},
{
"name": "num",
"value": 100,
"original_value": 100
},
{
"name": "filter",
"value": 0,
"original_value": 0
},
{
"name": "site",
"value": "GoogleSite",
"original_value": "GoogleSite"
},
{
"name": "oe",
"value": "UTF-8",
"original_value": "UTF-8"
},
{
"name": "partialfields",
"value": "",
"original_value": ""
},
{
"name": "ip",
"value": "10.10.10.10",
"original_value": "10.10.10.10"
},
{
"name": "",
"value": "",
"original_value": ""
}
],
"Q": "test",
"VER": 3.2,
"TM": 0.015718
}
}
15:41

03/03/2009

Thanks for the reply, Jean. Though there is an error in this "cleansed" version of my JSON, it still does not work. I did a lot more coding and dumbed it down quite a bit. I still was not able to get any named JSON elements to appear in the grid. I even used the examples verbatim from the documentation and it seems that neither the named elements or indexed ones work. Again, I could be missing something, but I suspect, too, there might be a bug ...
Has anyone been able to get named elements working? If so, can they be deeply nested and not just top level?
thanks!
bill
16:20

09/12/2008

Hi,
I think jqggrid wants a rather flat json file - see grid.base.js (around line 800): drows = data[ts.p.jsonReader.root]; - to me it looks like toplevel. So as I said, I think you should write a wrapper (wrapper.php):
<?php
$a = json_decode(file_get_contents($_GET["filename"]),true);
echo json_encode(array(”items”=>$a["GSP"]["RES"]["R"][0]["MT"]));
?>
and call it within your jqgrid (some parameters modified):
url:'wrapper.php?filename=http://somesite.com/wiredjsonfile.json',
colModel :[
{name:'Vvv', index:'corpid', width:100, jsonmap:"V"},
{name:'Nnn', index:'title', width:300, jsonmap:"N"}
],
jsonReader:{
root : “items”,
repeatitems: false,
}
take care
jean
Most Users Ever Online: 715
Currently Online:
49 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