jqGrid treegrid填充了本地数据 - jsonmap无法正常工作

时间:2013-05-09 00:44:08

标签: jqgrid

我正在使用本地数据加载treegrid。出于某种原因,jqGrid显示基于“name”属性的单元格值,而不是colModel的“jsonmap”属性。

这是网格和本地数据的简化版本。使用以下配置,我在“Qty”列中得到空值。但是,如果在“mydata”中我将“qty1”更改为“qty”,我会在“Qty”列中获取值。

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
   }) ;

非常感谢任何投入!

1 个答案:

答案 0 :(得分:2)

问题是您使用datatype: "local"并且jsonmap将不会使用{(3}} jqGrid代码。

我建议您改为使用datatype: "jsonstring"(有关代码示例,请参阅the lines)。

the answer提供代码的固定版本。它显示

enter image description here

它使用代码

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
 });