开发者

Unable to load json data with jqgrid, although jsonstring works fine

I have a jqgrid that I'd like to populate with my json, but I can't get it to work. I think my json is fine since the grid is working when supplying the json as a string (datatype:jsonstring). The thing is, I don't get any errors from jqgrid, which makes it hard to debug.

Here's my json (validated with jslint):

{ "total":"1", "page":"1", "records":"5", "rows": [ {"id" :"1", "cell" :["Modulex", "", "", "", ""]}, {"id" :"2", "cell" :["Lemoltech", "", "", "", ""]}, {"id" :"3", "cell" :["Isothermic", "", "", "", ""]}, {"id" :"4", "cell" :["Renova", "", "", "", ""]}, {"id" :"5", "cell" :["Natart Juvenile", "", "", "", ""]} ] }

And here's my config

$("#list").jqGrid({
    url:'/tempajax/',
    datatype: 'json',
    colNames:['Nom','Adresse','Ville','Tel','Courriel'],
    colModel :[ 
      {name:'company_name', ind开发者_开发百科ex:'company_name', width:55}, 
      {name:'address', index:'address', width:90},
      {name:'city', index:'city', width:90},
      {name:'telephone', index:'telephone', width:80}, 
      {name:'email', index:'email', width:80}, 
    ],
    autowidth: true,
    pager: '#pager',
    rowNum:10,
    viewrecords: true,
    gridview: true,
    height: '100%'
});

This is my first post here, so I hope to have supplied enough information for you guys to help, if not just ask.

Thanks a lot for your help!


Your JSON result doesn't match with what you're configuring your jqGrid to consume.

Your jqGrid is expecting a JSON result that has company_name, address, city, telephone, and email as fields, but your data is bringing back id and cell, and even then it's nested inside the top json result, which has total, page, records, and rows. Either way, it's not lined up with your jqGrid.


I fixed my problem, the json was fine afterall. The server was throwing a 404 code, even though the output was good. This prevented jqGrid from even parsing the json. I hope this will be helpfull to others as well!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜