【问题标题】:JQgrid not showing data while rows are generatingJQgrid在生成行时不显示数据
【发布时间】:2015-09-05 04:16:39
【问题描述】:

Jqgrid 不显示 JSON 数据,但是正在生成行

服务器端代码:

public JsonResult Denominations()
{
.
.
int counter = 0;
var jsonData = new
{
total = result.UserObject.Count,
page = 1,
rows = (
      from p in result.UserObject
      select new
      {
            id = ++counter,
            cell = new string [] { 
                   p.CurrencyID.ToString(), 
                   p.DenominationID.ToString(), 
                   p.DenominationName.ToString(), 
                   p.DenominatorCount.ToString(), 
                   p.Multiplier.ToString(), 
                   p.TenderID.ToString()
                     }
                 }).ToArray()

            };
            return Json(jsonData, JsonRequestBehavior.AllowGet);
}

服务器端的数据如下: {"total":1,"page":1,"rows":[{"id":1,"cell":["1","1","Penny","0","0.0100", "1"]}]}

JavaScript 代码:

$("#denominators").jqGrid({
        url: '/Denominations?tenderid=1&currencyid=1',
        contentType: "application/json",
        datatype: "json",
        jsonReader: {
            root: 'rows',
            page: 'page',
            total: 'total',
            repeatitems: false,
            cell: 'cell',
            id: 'id',
            userdata:'userdata'
        },
        mtype: "GET",
        colNames: ["CurrencyID", "DenominationID", "TenderID", "Multiplier", "DenominationName", "DenominatorCount"],
        colModel: [
            { name: "currencyid", width: 80, align: "center" },
            { name: "denominationid", width: 90, align: "center" },
            { name: "tenderid", width: 250 },
            { name: "multiplier", width: 250 },
            { name: "denominationname", width: 95 },
            { name: "denominatorcount", width: 95 },
        ],
        height: 'auto',
        loadonce: true,
        sortname: "DenominationID",
        sortorder: "desc",
        viewrecords: true,
        gridview: true,
        autoencode: true
    });

查看:

<table id="denominators" ></table>

视图创建带有列标题的网格,但是生成了行,但行没有任何数据 int。

【问题讨论】:

    标签: json knockout.js jqgrid jsonreader


    【解决方案1】:

    你用错了jsonReader。确切地说,repeatitems: false 的属性是错误的。表示rows数组中每一项的格式为

    {
        "currencyid": "1",
        "denominationid": "1",
        "tenderid": 1,
        "denominationname": "Penny",
        "denominatorcount": "0",
        "multiplier": "0.0100"
    }
    

    你使用

    {
        "id": 1,
        "cell": [
            "1",
            "1",
            "Penny",
            "0",
            "0.0100",
            "1"
        ]
    }
    

    相反。所以你应该删除jsonReader,因为输入数据的格式对应于默认的jsonReader,但你仍然需要重新排列网格的列或更改你在cell数组中放置的项目的顺序,以便它对应于顺序colModel 中的列数。

    补充说明:total 使用了错误的值。它应该是页数。顺便说一句,您使用loadonce: true。在这种情况下,您可以从响应中删除 "total":1,"page":1 部分并仅返回 named 项的数组。如果项目,您应该只选择与属性名称相同的列名称。

    【讨论】:

      猜你喜欢
      • 2016-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多