0

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 を生成しませんでした。

4

1 に答える 1

0

使い方が間違っていjsonReaderます。プロパティが正確であることrepeatitems: falseは 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するアイテムの順序を変更して、の列の順序に対応させる必要があります。cellcolModel

追加の注意事項: に間違った値を使用していますtotalページ数である必要があります。ちなみに使ってるloadonce: true。その場合"total":1,"page":1、応答から一部を削除して、名前付きアイテムの配列を返すだけです。アイテムの場合は、プロパティの名前と同じ列の名前を選択する必要があります。

于 2015-06-19T09:05:31.407 に答える