0

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

这是网格和本地数据的简化版本。使用以下配置,我在“数量”列中得到空值。但是,如果在“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
   }) ;

将不胜感激任何投入!

4

1 回答 1

2

问题是你使用datatype: "local"jsonmap不会使用的情况下(见jqGrid代码)。

我建议您datatype: "jsonstring"改用(请参阅代码示例的答案)。

该演示提供了您的代码的固定版本。它显示

在此处输入图像描述

它使用代码

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
 });
于 2013-05-09T18:20:01.780 回答