使用setGridParam将json数据加载到jqgrid中

Bre*_*cht 3 jqgrid

我在使用setGridParam设置jqgrid的url时遇到了一些问题.

我收到消息:"f未定义".

我的设置:

       $("#prices").jqGrid({
    colModel: [
           ...
        ],
    pager: jQuery('#pricePager'),
    ajaxGridOptions: { contentType: "application/json" },
    mtype: 'POST',
    loadonce: true,
    rowTotal: 100,
    rowNum: -1,
    viewrecords: true,
    caption: "Prices",
    height: 300,
    pgbuttons: false,
    multiselect: true,
    afterInsertRow: function (rowid, rowdata, rowelem) {
        // ...
    },
    beforeSelectRow: function (rowid, e) {
      // ...
    },
    onSelectRow: function (rowid, status) {
       // ...
    }
}); 
Run Code Online (Sandbox Code Playgroud)

获取数据:

$("#prices").setGridParam({ datatype: 'json', page: 1, url: '@Url.Action("GridDataPrices")', postData: JSON.stringify(selections) });

$("#prices").trigger('reloadGrid');
Run Code Online (Sandbox Code Playgroud)

响应是非编码的json:

{"total":1,"page":1,"records":100,"rows":[{"id":160602948,"StartDate":"\/Date(1311717600000)\/","Duration":7,"Price":1076.0000,"Code":"code"},{"id":160602950,...}]}
Run Code Online (Sandbox Code Playgroud)

但是,我使用firebug得到以下消息:

"f未定义"

我首先使用addJSONData,但必须替换它,因为我想保留本地排序.

提前致谢.

Ole*_*leg 6

上传代码后,所有内容都将清除.你的主要错误是以下几点:

  • 你应该包含datatype: 'local'在jqGrid中.默认值为'xml'.
  • JSON数据已命名属性,因此您必须使用jsonReader: { repeatitems: false }(有关详细信息,请参阅文档)
  • colModel在JSON数据中使用"ArivalCodeWay" 和"ArrivalCodeWay".所以你应该修复相应的jqGrid列的名称
  • date"\/Date(1312840800000)\/"您应该包含formatter:'date'在相应列中的格式解码.
  • 以同样的方式,我发现包含formatter:'int', sorttype:'int'在"持续时间"列和sorttype:'number', formatter:'number', formatoptions: { decimalPlaces:4, thousandsSeparator: "," }"价格"列中.
  • 如果您使用JSON.stringify,则应包含json2.js以确保您的代码可以在所有Web浏览器中使用.

您可以在此处找到修改后的演示(包括其他一些小改动).如果单击"单击我"按钮,将加载网格包含.