JQgrid saves and restores an object from a column

You can save a complex object in a column and restore 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" }); 

If I try to access addres:

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

Then I get the "object of the object", but this is a string !!! I can not: myaddress.data1

Any recommendation

+4
object hidden jqgrid
Oct 17 '12 at 11:32
source share
2 answers

If I understand your problem correctly, 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 a hidden "address" column. This way, you are not creating a hidden column in the table to store any special row-specific data. You should just populate the data as you would, as usual: using the data option for 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 case, all data will be stored in the internal parameter data jqGrid. You can use $("#rowed5").jqGrid("getGridParam", "data") to return all the data or use $("#rowed5").jqGrid("getLocalRow", rowid) to return data only the specified strings.

A small demonstration demonstrates a lively approach. Data is displayed on one line per page. Thus, you can go to the next page and change the data by editing the cell. After saving the information, the โ€œaddressโ€ from the current cell will be displayed.

+3
Oct 17 '12 at 12:16
source share

I just solved the problem. The main problem was that I had to load the data as follows:

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

You do not 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]); } 
0
Oct 17
source share



All Articles