0

我想将 jqGrid 集成到 asp.net 网页中。我得到了 JSON 格式的数据。但是在渲染没有数据的页面网格时。

我的书面代码如下。

JqG​​ridExample.aspx

    jQuery("#jsonmap").jqGrid({

     url: 'GetData.aspx',
     datatype: 'json',
     colNames: ['ID', 'Name', 'Active', 'Gender'],
     colModel: [
       { name: 'id', index: 'id', width: 35, editable: false, editoptions: { readonly: true, size: 10} },
       { name: 'name', index: 'name', width: 150, align: "left", editable: true, size: 100 },
       { name: 'isClosed', index: 'isClosed', width: 100, align: 'left', editable: true, edittype: "checkbox", editoptions: { value: "true:false", formatter: "checkbox"} },
       { name: 'gender', index: 'gender', width: 100, formatter: 'select', editable: true, edittype: "select", editoptions: { value: "0:select;1:male;2:female"} }
     ],
     rowNum: 10,
     rowList: [2, 5, 10, 15],
     pager: '#pjmap',
     sortname: 'id',
     sortorder: "desc",
     viewrecords: true,
     jsonReader: { repeatitems: false, cell: "", id: "0" },
     width: 600,
     caption: 'First jqGrid',
     height: '100%', viewrecords: true, fixed: true, gridview: true, loadonce: true
   });

<table id="jsonmap">
</table>
<div id="pjmap">
</div>

我从中得到的数据getdata.aspx

{"total":1,"page":1,"records":5,"rows":[{"Name":"John","Id":1,"Gender":1,"IsClosed":false},{"Name":"Abel","Id":2,"Gender":1,"IsClosed":false},{"Name":"Aaron","Id":3,"Gender":1,"IsClosed":true},{"Name":"Tsion","Id":4,"Gender":2,"IsClosed":true},{"Name":"Mussie","Id":5,"Gender":2,"IsClosed":true}]}

在 jqGridExample.aspx 数据上的渲染网格未显示。

提前致谢..

4

1 回答 1

1

您应该使用与 JSON 数据中的名称完全对应的name属性。colModel因此,您应该更改name: 'id'name: 'Id', name: 'name'to name: 'Name', name: 'isClosed'toname: 'IsClosed'name: 'gender'to name: 'Gender'。您可以从所有属性中删除所有index属性colModel或对所有属性进行相同的更改index

此外,您应该key: trueId.colModel

于 2013-03-16T09:31:18.610 回答