dongliang1865 2016-04-14 09:41
浏览 119
已采纳

jqgrid自定义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"]},
      ...
  ]
}

Here is the JS grid definition:

$("#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));
    }
});

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:

enter image description here

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

  • 写回答

1条回答 默认 最新

  • dongqi19827 2016-04-14 10:56
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题