views:

1788

answers:

2

Dear all, Let's say I have a perfectly fine JSON serialized string, like so:

{"Page":0,"Total":0,"Records":0,"Rows":[{/*blah*/}]}

This isn't returned by a particular URL, it's just sitting there, happy as it can be (harcoded). How do I add it to jqGrid? I've tried every conceivable variation of the loadComplete function or a addJSONData variant, latest:

 loadComplete: function(){ 
   var mygrid = jQuery("#grid")[0];
   var o = eval("(" + {"Page":0,"Total":0,"Records":0,"Rows":[{/*blah*/}]} + ")");
   mygrid.addJSONData(o.result);
}

but it won't work. It has worked when I've returned the JSON by a URL, however. Am I missing something when I use:

 dataType:"json", 
 url: "/SomePageThatDoesntDoAnything"

I have a sneaky feeling it might have to do with having to reload the grid. Any help will be greatly appreciated.

+1  A: 

If I am looking at the correct plugin you have a demo for loading static data here. Under Items/ loading data / array data

Elzo Valugi
I'm looking to populate the grid with JSON, not array data.
Rio
There is a demo for json as well. The only issue is that they prepared the JSON scenario for an Ajax call. You can place your Json object in a txt file and call Query("#list2").jqGrid({ url:'yourfile.txt', datatype: "json" ....
Elzo Valugi
I'm not looking at saving it into a text file, unfortunately.
Rio
A: 

check this link: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data

you need to set up the following jqgrid properties:

datatype: "jsonstring", datastr : JSON.stringify(JSON_OBJECT, function replacer(key, value){return value});, //

JSON.stringify function is defined on json.orgl site.

Sergio Gtz