2012-11-23 81 views
0

有人可以帮我。我正在尝试使用JQGrid动态呈现使用json的列和数据。列似乎正在出现,但没有行数据。JQGrid显示列但没有行数据

下面是我从我的服务返回JSON:

{ 
    "total": 1, 
    "page": 1, 
    "records": 1, 
    "rows": [ 
     { 
      "id": 29291, 
      "cell": [ 
       "Jim", 
       "1", 
       "2" 
      ] 
     } 
    ], 
    "columns": [ 
     "Name", 
     "30/10/2012", 
     "23/10/2012" 
    ], 
    "columnmodel": [ 
     { 
      "name": "Name", 
      "index": "Name", 
      "align": "left", 
      "width": 25 
     }, 
     { 
      "name": "30/10/2012", 
      "index": "30/10/2012", 
      "align": "left", 
      "width": 25 
     }, 
     { 
      "name": "23/10/2012", 
      "index": "23/10/2012", 
      "align": "left", 
      "width": 25 
     } 
    ] 
} 

而且我现在用的就是JavaScript的:

$.ajax({ 
    type: "GET", 
    url: "ListData?ID=1", 
    datatype: "json", 
    success: function(result){ 
     $("#customgrid").jqGrid({ 
       datatype: "json", 
       colNames: result.columns, 
       colModel: result.columnmodel, 
       data: result.rows, 
       width: 800, 
       pager: "#customgridpager", 
       viewrecords: true, 
       sortable: true, 
       gridview: true, 
     }); 
    }, 
}); 

任何帮助将不胜感激。

回答

2

您只需对代码进行一些小改动。您需要先更改$.ajax呼叫中的打字错误:将datatype更改为dataType。那么您需要更改datatype: "json"datatype: "jsonstring"data: result.rowsdatastr: result。完整的代码,我会建议您低于:

$.ajax({ 
    type: "GET", 
    url: "NiallGray.json", 
    dataType: "json", 
    success: function (result) { 
     $("#customgrid").jqGrid({ 
      datatype: "jsonstring", 
      colNames: result.columns, 
      colModel: result.columnmodel, 
      datastr: result, 
      width: 800, 
      pager: "#customgridpager", 
      viewrecords: true, 
      sortable: true, 
      gridview: true, 
      rowNum: 10000, 
      height: "auto" 
     }); 
    } 
}); 

演示的修改后的版本是here

enter image description here

+0

传奇!非常感谢。周末愉快。 –