【问题标题】:Alter the data before displaying it in the grid在网格中显示之前更改数据
【发布时间】:2012-10-23 19:20:03
【问题描述】:

我有一个由 JSON 请求填充的 jqGrid,问题是请求以 base64 编码数据返回服务器,我需要在将数据分配给网格之前对其进行解码。

基本上我需要这样的东西:

$( "#grid" ).jqGrid( {
    datatype: "json",
    colNames: ["id", "Num", "Name", "Code"],
    colModel: [
        { name: "id", index: "id", width: 30, sortable: true, resizable: false },
        { name: "num", index: "num", width: 150, sortable: true, resizable: false },
        { name: "name", index: "name", width: 250, sortable: true, resizable: false },
        { name: "code", index: "code", width: 150, sortable: true, resizable: false },
    ],
    multiselect: true,
    width: "760",
    height: "100%",
    heightMetric: "%",
    shrinkToFit: false,
    rowNum: 20,
    rowList: [20,30,60],
    pager: "#pager",
    sortname: "id",
    viewrecords: true,
    sortorder: "asc",
    headertitles : true,
    caption: "Loading...",
    beforeProcessing: function(data){
       data = decompress(data); // Like this
    }
})

【问题讨论】:

    标签: javascript jqgrid encode


    【解决方案1】:

    回调函数beforeProcessing 是您可以实现所有需要的正确位置。确切的实现取决于服务器返回的数据格式。如果使用datatype: "json",那么从服务器返回的数据通常是一个序列化为 JSON 字符串的对象。 jqGrid 在内部使用jQuery.ajax,它会自动解码 JSON 字符串并将其转换回对象。所以beforeProcessing回调的输入data参数就是服务端返回的对象。如果你不使用 jqGrid 的任何额外的jsonReader 选项,那么 jqGrid 将等待here 描述的标准格式的输入数据。因此,您只需根据从服务器返回的输入数据填写data 对象的预期属性(rowspagetotalrecords)。您没有发布任何从服务器返回的数据的示例,因此我无法给您提供更详细的示例。

    【讨论】:

    • 我在寻找this
    • @byoigres:抱歉,我不明白你的意思。
    猜你喜欢
    • 2015-01-05
    • 2012-03-24
    • 2020-01-12
    • 2013-04-24
    • 1970-01-01
    • 1970-01-01
    • 2011-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多