前台:
$("#grid-table").jqGrid({ url:"test1.php", datatype:"json", mtype:"get", height:"auto", colNames:["name",'age','sex'], colModel:[ {name:"name",index:"name",180}, {name:"age",index:"age",180}, {name:"sex",index:"sex",180} ], treeGrid : true, ExpandColumn:"name", treeGridModel:"adjacency" });
treeGridModel默认是左右值,不用需要赋值“adjacency”
php:
<?php $a=""; $nodeid=$_GET["nodeid"]; if($nodeid=="2"){ $arr=array('id'=>1,'cell'=>array('name'=>232,'age'=>1,'sex'=>'x','level'=>1,'parent'=>2,'isLeaf'=>false,'expanded'=>true,'loaded'=>false)); $arr1=array('id'=>4,'cell'=>array('name'=>242,'age'=>1,'sex'=>'x','level'=>1,'parent'=>2,'isLeaf'=>true,'expanded'=>false,'loaded'=>true)); }else if($nodeid=="1"){ $arr=array('id'=>11,'cell'=>array('name'=>242,'age'=>1,'sex'=>'x','level'=>2,'parent'=>1,'isLeaf'=>true,'expanded'=>false,'loaded'=>false)); $arr1=array('id'=>41,'cell'=>array('name'=>242,'age'=>1,'sex'=>'x','level'=>2,'parent'=>1,'isLeaf'=>true,'expanded'=>false,'loaded'=>false)); } else{ $arr=array('id'=>2,'cell'=>array('name'=>22,'age'=>1,'sex'=>'x','level'=>0,'parent'=>0,'isLeaf'=>false,'expanded'=>true,'loaded'=>false)); $arr1=array('id'=>3,'cell'=>array('name'=>322,'age'=>1,'sex'=>'v','level'=>0,'parent'=>0,'isLeaf'=>true,'expanded'=>true,'loaded'=>false)); } $a=array("rows"=>array($arr,$arr1)); echo json_encode($a); ?>
level:层级
parent:父级
isLeaf:是否是叶子节点
expanded:是否展开
Loaded:是否异步加载