jqGrid不显示返回的JSON数据

时间:2014-10-12 22:18:51

标签: javascript jquery ajax json jqgrid

我在ASP.NET页面中使用jqGrid。在.aspx页面中,我有 -

<div id="divMy" style="width: 100%; overflow: auto;">
    <div id="divMyTable" style="width: 97%; display: none;">
        <table id="MyTable">
            <tr>
                <td></td>
            </tr>
        </table>
        <div id="divMyTablePager"></div>
    </div>
</div>

在.js文件中,我有 -

var CASortInfo = {
    sortname: $('#MyTable').jqGrid('getGridParam', 'sortname'),
    sortorder: $('#MyTable').jqGrid('getGridParam', 'sortorder'),
    page: $('#MyTable').jqGrid('getGridParam', 'page'),
    rows: $('#MyTable').jqGrid('getGridParam', 'rows')
};


    $("#MyTable").jqGrid({
        url: "../Services/My.asmx/ReadMyTable",
        datatype: 'json',
        mtype: 'POST',
        prmNames: {
            search: "isSearch",
            nd: null,
            rows: "PageSize",
            page: "PageNumber",
            sort: "sortField",
            order: "sortOrder"
        },
        postData: { ID: $('#hfID').val() },
        ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
        serializeGridData: function (postData) {
            return JSON.stringify(postData);
        },
        colNames: ["", "My", "Date Created", "Notes", "Action"],
        colModel: [
            { name: "MyID", index: "MyID", resizable: false, hidden: true },
            { name: "MyName", index: "MyName", resizable: false, width: 250 },
            { name: "CreatedOn", index: "CreatedOn", resizable: false },
            { name: "Notes", index: "Notes", resizable: false },
            { name: "Buttons", formatter: ActionButtons, width: 70 }
        ],
        sortname: "CreatedOn",
        sortorder: "asc",
        ignoreCase: true,
        autowidth: true,
        shrinkToFit: true,
        height: "auto",
        pager: "#divMyTablePager",
        toppager: true,
        rowNum: 20,
        rowList: [5, 10, 20, 50],
        viewrecords: true,
        gridview: true,
        rownumbers: false,
        hoverrows: true,
        multiselect: false,
        jsonReader: {
            root: function (obj) { return obj.d.rows; },
            page: function (obj) { return obj.d.page; },
            total: function (obj) { return obj.d.total; },
            records: function (obj) { return obj.d.records; },
            repeatitems: false,
            id: "0"
        },
        beforeRequest: function () {
            CASortInfo = {
                sortname: $('#MyTable').jqGrid('getGridParam', 'sortname'),
                sortorder: $('#MyTable').jqGrid('getGridParam', 'sortorder'),
                page: $('#MyTable').jqGrid('getGridParam', 'page'),
                rows: $('#MyTable').jqGrid('getGridParam', 'rows')
            };
        },
        gridComplete: function () {

            $('#MyTable').jqGrid('setGridParam', {
                sortname: CASortInfo.sortname,
                sortorder: CASortInfo.sortorder,
                page: CASortInfo.page,
                rows: CASortInfo.rows
            });


                $("#divMyTable").show();
                $("#MyTable").setGridWidth($("#divMyTable").width());
        }
    });

我可以看到响应的JSon数据为 -

{"d":{"__type":"Core.DTO.JQGridModel","total":"1","page":"1","records":"1","rows":[{"MyID":"627d6ca3-5bbc-4aa8-9e53-76afe4869ae2","MyName":"This\u0027s a test.","CreatedOn":"\/Date(1394135983350)\/","Notes":"Yes","isActive":null}]}}

我可以看到在gridComplete中遇到断点。用数据显示数据网格需要做些什么?

谢谢,

1 个答案:

答案 0 :(得分:0)

刚刚发现我在divMyTable中搞砸了这个案子。纠正后,它正在工作。感谢