JQgrid not showing data while rows are generating

142 views Asked by At

Jqgrid is not showing JSON data, however rows are generating

Server side code:

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);
}

Data from server side is like this: {"total":1,"page":1,"rows":[{"id":1,"cell":["1","1","Penny","0","0.0100","1"]}]}

JavaScript code:

$("#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
    });

View:

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

View creates the grid with column header however rows are generated but rows did not any data int.

1

There are 1 answers

0
Oleg On BEST ANSWER

You use wrong jsonReader. To be exactly the property repeatitems: false is false. It means that the format of every item in rows array is

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

You use

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

instead. So you should remove jsonReader because the format of input data corresponds the default jsonReader, but you need still reorder the columns of the grid or change the order of items which you place in cell array so that it corresponds the order of columns in colModel.

Additional remarks: you use wrong value for total. It should be the number of pages. By the way you use loadonce: true. In the case you can remove "total":1,"page":1 part from the response and just return array of named items. You should just choose the names of columns the same as the names of properties if the items.