0

我试过了,我终于放弃了试图弄清楚为什么我的 jqGrid 不显示数据。

让我一步一步尝试:以下是脚本中包含的内容...

<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<link href="../../Content/themes/redmond/jquery-ui-1.8.2.custom.css" rel="stylesheet" type="text/css" />
<link href="../../Content/themes/redmond/ui.jqgrid.css" rel="stylesheet" type="text/css" />
<link href="../../Content/themes/base/jquery.ui.button.css" rel="stylesheet" type="text/css" />

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script>

<script src="../../Scripts/grid.locale-en.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.jqGrid.min.js" type="text/javascript"></script>

JSON 返回:

{
"total": 1,
"page": 1,
"records": 1,
"rows": [
    {
        "id": "0001",
        "cell": [
            "0001",
            "XXXXX",
            "XXXX",
            "XXX",
            "XXX",
            "XXXXX",
            "XXXX",
            "7/27/2012 1:46:22 PM",
            "XXXXX",
            "7/30/2012 3:48:25 PM"
        ]
    }
]

}

jqGrid代码如下:

jQuery(function ($) {
    jQuery('#tblManageApplication').jqGrid({
        url: '/AdminView/ManageApplicationsJQGridData',
        datatype: 'json',
        loadError: function (xhr, status, error) { alert(status + " " + error); }, 
        mtype: 'GET', 
        colNames: ['Application ID', 'Application Name', 'Application Description', 'Country Code', 'Country Name', 'Source Indicator Code', 'Insert User ID', 'Insert User Timestamp', 'Update User ID', 'Update User Timestamp'],
        colModel: [
                    { name: 'ApplicationID', jsonmap: 'cell.ApplicationID', width: 150 },
                    { name: 'ApplicationName', jsonmap: 'cell.ApplicationName', width: 200 },
                    { name: 'ApplicationDescription', jsonmap: 'cell.ApplicationDescription', width: 250 },
                    { name: 'CountryCode', jsonmap: 'cell.CountryCode', width: 100 },
                    { name: 'CountryName', jsonmap: 'cell.CountryName', width: 100 },
                    { name: 'SourceIndicatorCode', jsonmap: 'cell.SourceIndicatorCode', width: 100 },
                    { name: 'InsertUserID', jsonmap: 'cell.InsertUserID', width: 100 },
                    { name: 'InsertUserTimestamp', jsonmap: 'cell.InsertUserTimestamp', width: 100, formatter: 'date', formatoptions: { newformat: 'd-m-Y' }, datefmt: 'd-m-Y' },
                    { name: 'UpdateUserID', jsonmap: 'cell.UpdateUserID', width: 100 },
                    { name: 'UpdateUserTimestamp', jsonmap: 'cell.UpdateUserTimestamp', width: 175, formatter: 'date', formatoptions: {newformat: 'd-m-Y'}, datefmt: 'd-m-Y' }
                  ],
        pager: jQuery('#pager'),
        sortName: 'ApplicationID',
        rowNum: 10,
        jsonReader: { repeatitems: false },
        rowList: [10, 20, 50],
        sortorder: 'desc',
        height: 300,
        width: 1200,
        caption: 'Manage Applications',
        onCellSelect: function (rowid, index, contents, event) {
            alert('onCellSelect: ' + index + ' : ' + contents);
        },
        success: function (data, textStatus) {
            if (textStatus == 'success') {
                alert('Successful');
            }
        },
        error: function (data, textStatus) {
            alert('An error has occurred');
        }
    });
});

想添加相应的HTML供您参考:

<table id="tblManageApplication"></table>
<div id="pager"></div>

任何帮助将不胜感激。

4

2 回答 2

2

首先,您能否确认您从控制器发送的数据和 colModal 名称按字母顺序相同?

第二次检查你的 json 阅读器

检查这个链接

http://www.ok-soft-gmbh.com/jqGrid/ipInfo.htm 我认为您需要在这里指定一些东西,例如 id 和记录。

于 2012-07-31T02:32:57.083 回答
0

您的代码中的主要错误是jsonReader: { repeatitems: false }选项的使用,并且jsonmap在您根本不需要的情况下。您以标准格式生成数据。因此,您必须删除选项才能填充网格。

此外,我建议您将数据格式更改为ISO 8601格式(您可以DateTime在服务器代码上使用“o”格式)或至少定义正确srcformat

formatoptions: {srcformat: 'm/d/Y g:i:s A', newformat: 'd-m-Y'}

该演示演示了我上面描述的更改有效。

于 2012-07-31T10:20:04.243 回答