JQgrid从列保存和恢复对象 [英] JQgrid save and recover object from column

查看:260
本文介绍了JQgrid从列保存和恢复对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以将复杂的对象保存到列中,然后再进行恢复.

It is posible to save a complex objet into a column and to recover it after.

这是一个示例: 杰森:

This is an example: Json:

[{"datamain":"mydata",
       "address":{"data1":15,"data2":0.0,"data3":"1000"}}
}]

Jqgrid:

jQuery("#rowed5").jqGrid({  
        datatype: "local",
        loadtext:"Loading...",
        colNames:['Name',
                  'obaddress'],
        colModel:[
        {name:'datamain',index:'datamain', width:200,editable: true,edittype:'text'},
        {name:'address',index:'address', width:30, editable: false,hidden : true,edittype:'text'}
                ],
        cellsubmit: "clientArray",  
        pager:"#pager"
    });

如果我尝试访问地址:

 var rowData = $("#rowed5").getRowData(rowid);
var myaddress= rowData['address'];

然后我得到'[object Object]',但这是一个字符串!!!我不能做:myaddress.data1

Then I get '[object Object]' but it is a string!!! I can not do: myaddress.data1

任何推荐?

推荐答案

如果我正确理解了您的问题,则可以执行以下操作:

If I correctly understand your problem you can do the following:

var rowData = $("#rowed5").jqGrid("getLocalRow", rowid);
alert("data3=" + rowData.address.data3);

通过保存address部分的方式,您无需创建隐藏列"address".因此,您不会在表中创建任何隐藏列来保存任何特定于行的自定义数据.您应该像通常那样填充数据:使用jqGrid的data选项:

By the way to save the address part you don't need to create hidden column "address". So you don't create any hidden column in the table to hold any row specific custom data. You should just fill the data like you do as typically: using data option of jqGrid:

var mydata = [
    {
        id: "10",
        "datamain": "mydata",
        "address": {"data1": 15, "data2": 0.0, "data3": "1000"}
    },
    {
        id: "20",
        "datamain": "mydata2",
        "address": {"data1": 18, "data2": 0.1, "data3": "3000"}
    }
];

$("#rowed5").jqGrid({
    datatype: "local",
    data: mydata,
    colNames: ['Name'],
    colModel: [
        {name: 'datamain', width: 300, editable: true}
    ],
    height: "auto",
    ...
});

如果所有数据将保存在jqGrid的内部data参数中.您可以使用$("#rowed5").jqGrid("getGridParam", "data")返回所有数据,也可以使用$("#rowed5").jqGrid("getLocalRow", rowid)仅返回指定行的数据.

In the case all the data will be saved in the internal data parameter of jqGrid. You can use $("#rowed5").jqGrid("getGridParam", "data") to return all the data or use $("#rowed5").jqGrid("getLocalRow", rowid) to return the data of the specified row only.

小型演示实时演示了该方法.数据每页显示一行.因此,您可以转到下一页并使用单元格编辑来修改数据.保存地址"后,将显示当前单元格中的信息.

The small demo demonstrate the approach live. The data are displayed one row per page. So you can go to the next page and modify the data using cell editing. After saving the "address" information from the current cell will be displayed.

这篇关于JQgrid从列保存和恢复对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆