0

我对 jqGrid 很陌生。我正在尝试使用 asp.net web api 加载简单的 jqgrid。api 发回 emailDto 的列表。emailDto 是具有 3 个公共属性的普通类

问题是 jqgrid 没有被填充。很感谢任何形式的帮助。

function dataBindToGrid() {
        var lastsel;
        $("#emailgrid").jqGrid({
            url: '/api/email/',
            datatype: "json",
            mytype: 'GET',
            ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
            colNames: ['Address ID', 'Type', 'Email'],
            colModel: [{ name: 'Address_ID', width: 70, primaryKey: true, editable: false, sortable: false, hidden: false, align: 'left' },
                    { name: 'Email_Type', width: 70, editable: true, align: 'left', sortable: false },
                    { name: 'Email_Address', width: 200, editable: true, align: 'left', sortable: false }

            ],
            onSelectRow: function (id) {
                if (id && id !== lastsel) {
                    var grid = $("#emailgrid");
                    grid.restoreRow(lastsel);
                    grid.editRow(id, true);
                    lastsel = id;
                }
            },
            //This event fires after all the data is loaded into the grid
            gridComplete: function () {
                //Get ids for all current rows
                var dataIds = $('#emailgrid').jqGrid('getDataIDs');
                for (var i = 0; i < dataIds.length; i++) {
                    //Put row in edit state
                    $("#emailgrid").jqGrid('editRow', dataIds[i], false);
                }
            },
            rowNum: 3,
            viewrecords: true,
            caption: "Email Addresses"
        });
    }
4

2 回答 2

0

当为 jsondatatype 配置时,jqGrid 需要以下 json 格式的数据:

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

返回的数据必须与此匹配,否则它将不起作用。这是默认的 json 结构(您可以根据需要更改它)。根据您使用的浏览器,您应该能够看到 ajax 请求和响应以及在网格自身构建时发送和返回的数据(Firefox 使用 firebug,IE 使用开发人员工具栏)

按照这里

于 2012-07-06T01:53:09.347 回答
0

解决了!

刚刚添加到下面的 jqGrid 中,它就可以工作了。

jsonReader: {
                repeatitems: false,
                page: function () { return 1; },
                root: function (obj) { return obj; },
                records: function (obj) { return obj.length; }
            },
于 2012-07-06T17:18:25.683 回答