2012-04-21 62 views
0

我想加載TreeGrid(jqGrid)的數組數據。但不知何故,層次結構不顯示。數據僅出現在扁平結構中。jQuery的 - 加載jqGrid - TreeGrid的陣列數據

代碼:

$("#list").jqGrid({ 
    treeGrid: true, 
    treeGridModel: 'adjacency', 
    ExpandColumn: 'label', 
    ExpandColClick: true, 
    datatype: 'local', 
    colNames:['Parent','Org','cd'], 
    colModel:[ 
     {name:'parent',id:'parent',index:'parent', width:250, hidden: true, 
      align: 'left', sortable: false, classes: 'indeling', title: false }, 
     {name:'label',id:'label',index:'label', width:250,align: 'left', 
      sortable: false, classes: 'indeling', title: false, visible: false}, 
     {name:'cd',id:'cd',index:'cd', width:100,align: 'left', sortable: false, 
      classes: 'indeling', title: false,visible: false } 
    ], 
    rowNum: 20000, 
    viewrecords: true, 
    height: "100%", 
    treeIcons: { leaf: 'ui-icon-document-b' }, 
    hoverrows: false 
}); 

然後我在陣列中添加的行格:陣列的

$('#list').jqGrid('addRowData',0,array[0]); 
$('#list').jqGrid('addRowData',1,array[1]); 

結構:

array=[{parent:"",label:"1",cd:"32"},{parent:"1",label:"2",cd:"42"}] 

誰能幫助?

回答

0

你會找到你的問題的答案here

你應該不要使用addRowData這是緩慢的,將主要是錯誤的使用。對於父節點,您應該使用parent: "null"parent: null。此外,您應該在TreeGrid的輸入數據中包含其他信息,例如level,isLeaf。所有節點都需要有loaded:true來保存本地節點。

在輸入中使用正確的項目順序很重要。該順序應該與完整展開樹中的項目順序相對應。所以所有的孩子都應該跟隨父母。

您應該從colModel中刪除未知屬性,如idvisible。您可以在the documentation中找到所支持的屬性列表。