Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use a JSON string or JSON object with jqGrid?

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
like image 524
learnerplates Avatar asked Sep 02 '10 15:09

learnerplates


1 Answers

got it. need to use datastr instead of url

datatype: 'jsonstring',
datastr: GetJSON(),
like image 154
learnerplates Avatar answered Oct 01 '22 18:10

learnerplates