Reputation: 465
I am loading a treegrid using local data. For some reason, jqGrid is displaying cell values based on "name" property and not "jsonmap" property of the colModel.
Here is a simplified version of the grid and the local data. With the below configuration, I get empty values in the "Qty" column. However, if in "mydata" I change "qty1" to "qty" I get values in the "Qty" column.
var mydata = {"rows":[
{id: 1221,name: "P1",qty1: "1", level: 0,parent: "NULL",isLeaf: false, loaded: true, expanded: true},
{id: 1222,name: "P1-Child",qty1: "2", level: 1,parent: 1221,isLeaf: true, loaded: true, expanded: true}
]};
jQuery("#bomTable").jqGrid({
treeGrid:true,
treeGridModel:'adjacency',
ExpandColumn:'name',
treedatatype: "local",
datatype: "local",
data: mydata,
jsonReader: {
repeatitems: false
},
colNames:['ID', 'Name', 'Qty'],
colModel:[
{name:'id', hidden: true},
{name:'name', index:'name'},
{name: 'qty', jsonmap: 'qty1', index: 'qty'}
],
width:'auto',
height:'auto',
shrinkToFit:false
});
jQuery("#bomTable")[0].addJSONData({
total: 1,
page: 1,
records: mydata.rows.length,
rows: mydata.rows
}) ;
Would greatly appreciate any inputs!
Upvotes: 0
Views: 2625
Reputation: 221997
The problem is that you use datatype: "local"
and jsonmap
will be not used in the case (see the lines of jqGrid code).
I recommend you to use datatype: "jsonstring"
instead (see the answer for the code example).
The demo provides the fixed version of your code. It displays
It uses the code
var mydata = {"rows": [
{id: 1221, name: "P1", qty1: "1", level: 0, parent: "NULL", isLeaf: false, loaded: true, expanded: true},
{id: 1222, name: "P1-Child", qty1: "2", level: 1, parent: 1221, isLeaf: true, loaded: true, expanded: true}
]};
$("#bomTable").jqGrid({
treeGrid: true,
treeGridModel: "adjacency",
ExpandColumn: "name",
treedatatype: "local",
datatype: "jsonstring",
datastr: mydata,
jsonReader: {
repeatitems: false
},
colNames: ["Name", "Qty"],
colModel: [
{name: "name"},
{name: "qty", jsonmap: "qty1"}
],
height: "auto",
sortname: "name",
shrinkToFit: false,
autoencode: true,
gridview: true
});
Upvotes: 2