views:

99

answers:

1

My jqGrid is work when my JSON data is in a static file, but if I copy the data to a var and then try to load the var into the jqGrid's url it doesn't show.

Can you pass a string into jqGrid

e.g. This works:

function GetJSON() {
    var jsonFile = "EntityWithChildren.json";
    return jsonFile;//returning a file works fine.
}

$("#jsonmap").jqGrid({
    url: GetJSON(),
    datatype: 'json',

this doesn't:

function GetJSON() {
    var json = '{"page":"1","total":"10",   "records":"10", "Entities": [       {"Fields":["Entity1", "field1", "11"]},     {"Fields":["", "field2", "22"]},        {"Fields":["Entity2", "field3", "33"]},     {"Fields":["ChildEntity1", "cfield1", "111"]}   ]}';
    return json; //doesnt work

}

$("#jsonmap").jqGrid({
    url: GetJSON(),
    datatype: 'json',
    //datatype: 'jsonstring',//this doesnt work either
A: 

got it. need to use datastr instead of url

datatype: 'jsonstring',
datastr: GetJSON(),
learnerplates
Exactly! You could find it in the documentation http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#json_string. If you answered yourself on your question and the problem is solved you should better mark your own answer as "accepted". It simplifies working with your question for other people.
Oleg