JQgrid save and recover object from column

喜欢而已 提交于 2019-12-04 09:14:27

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

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

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",
    ...
});

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.

I just resolved the problem. The main problem was that I have to load data on this way:

        jQuery("#rowed5")
        .jqGrid('setGridParam',
            { 
                datatype: 'local',
                data:mydata
            })
        .trigger("reloadGrid");

You don't have to do this:

       jQuery("#rowed5").jqGrid("clearGridData", true);
        for(var i=0;i < data.item.length;i++){
            jQuery("#rowed5").jqGrid('addRowData',i,data.item[i]);
        }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!