jqgrid自定义JSON数据没有错误,但不显示数据 [英] jqgrid custom JSON data no error but not showing data

查看:125
本文介绍了jqgrid自定义JSON数据没有错误,但不显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jqGrid已有一段时间了,我只是试图创建一个新的服务器端脚本以将数据返回到客户端网格.很多时候,我试图回到这些软件程序的基础上.我想将JSON数据返回到我的网格,只需将其加载一次而无需寻呼机.在参考文档此处之后,我尝试创建我的JSON字符串以匹配文档中的格式,例如:

I have been working with jqGrid for a while, and I was just trying to create a new server-side script to return data to a client-side grid. A lot of times I try to get back to the basics of these software programs. I wanted to return JSON data to my grid, just have it load once with no pager. After referencing the documentation here, I tried to create my JSON string to match the format from the docs, like this:

{ 
  "total": "xxx", 
  "page": "yyy", 
  "records": "zzz",
  "rows" : [
    {"id" :"1", "cell" :["cell11", "cell12", "cell13"]},
    {"id" :"2", "cell":["cell21", "cell22", "cell23"]},
      ...
  ]
}

这是JS网格定义:

$("#jqGrid").jqGrid({
    url:'/dataurl.php',
    shrinkToFit: true,
    autowidth: true,
    datatype: 'json',
    mtype: 'POST',
    postData:{
        'arg1':'load_data',
        'num_days':$('#num_of_days_input').val()
    },
    colNames:[
        'Ship_Date',
        'Insert/Label',
        'Customer',
        'JobNum',
        'QNTYOrdered',
        'DEL',
        'Ship_Type',
        'Carrier',
        'Time',
        'Status'
    ],
    colModel:[
        {width:20,name:'Ship_Date', index:'Ship_Date'},
        {width:20,name:'InsertorLabel', index:'InsertorLabel'},
        {width:20,name:'Customer', index:'Customer'},
        {width:20,name:'JobNum', index:'JobNum'},
        {width:20,name:'QNTYOrdered', index:'QNTYOrdered'},
        {width:20,name:'DEL', index:'DEL'},
        {width:20,name:'Ship_Type', index:'Ship_Type', edittype:'select', editoptions:{value:"Partial:Partial;Balance:Balance;Full:Full"}},
        {width:20,name:'Carrier', index:'Carrier', edittype:'select', editoptions:{value:"UPS:UPS;Fed Ex:Fed Ex;2D:2D;T&M:T&M;Cougar:Cougar"}},
        {width:20,name:'Time', index:'Time', edittype:'select', editoptions:{value:"before 7am:before 7am;7-9am:7-9am;9-12am:9-12am;12-3pm:12-3pm;after 3pm:after 3pm"}},
        {width:20,name:'Status', index:'Status', edittype:'select', editoptions:{value:"To Ship:To Ship;Ship Pending:Ship Pending"}}
    ],
    loadonce: true,
    sortname: 'Ship_Date',
    sortorder: 'asc',
    viewrecords: true,
    gridview: true,
    caption: 'Shipping Request',
    loadError: function(xhr, status, error){
        alert(xhr.responseText);
        alert(status);
        alert(error);
    },
    loadComplete: function(data){
        alert(JSON.stringify(data, null, 4));
    }
});

我已经使用loadError方法进行了很多调试,现在我没有遇到任何错误,可以看到我的数据是从服务器返回的.在我看来,格式是正确的:

I had done quite a bit of debugging using the loadError method, and now that I am getting no errors, I can see my data returned from the server. To me it looks like the format is correct:

但是,可惜的是,网格仍然在此处显示为空.我还缺少什么吗?谢谢!

But, alas, the grid still appears empty there. Am I still missing something? Thanks!

推荐答案

来自服务器的JSON响应的rows属性的值必须为数组,但是您可以使用object代替(它应该为"rows": [{}],但您改为使用"rows": {}).即使只有一项,也应该返回包含其中一项的数组.

The value of rows property of the JSON response from the server have to be array, but you use object instead (it should be "rows": [{}], but you use "rows": {} instead). Even if you have only one item you should still return the array with one of the item.

这篇关于jqgrid自定义JSON数据没有错误,但不显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆