直接上源码的js。测试可用。废话不多说!有问题留言,必回!!$(document).ready(function(){
var topicjson={
"response": [
{
"id": "1",
"elementName": "Grouping",
level:"0", parent:"", isLeaf:false, expanded:false, loaded:true
},
{
"id": "1_1",
"elementName": "Simple Grouping",
level:"1", parent:"1", isLeaf:true, expanded:false, loaded:true
},
{
"id": "1_2",
"elementName": "May be some other grouping",
level:"1", parent:"1", isLeaf:true, expanded:false, loaded:true
},
{
"id": "2",
"elementName": "CustomFormater",
level:"0", parent:"", isLeaf:false, expanded:true, loaded:true
},
{
"id": "2_1",
"elementName": "Image Formatter",
level:"1", parent:"2", isLeaf:true, expanded:false, loaded:true
},
{
"id": "2_1",
"elementName": "Anchor Formatter",
level:"1", parent:"2", isLeaf:true, expanded:false, loaded:true
}
]
},
grid;
// $('
').appendTo('#topics');var lastsel;
grid = jQuery("#treegrid2");
grid.jqGrid({
datastr: topicjson,
datatype: "jsonstring",
height: "auto",
loadui: "disable",
colNames: ["id","Items","url"],
colModel: [
{name: "id",width:200, hidden:false, key:true},
{name: "elementName", editable:true,width:250, resizable: false},
{name: "url",width:1, editable:true,hidden:true}
],
treeGrid: true,
treeGridModel: "adjacency",
ExpandColumn: "elementName",
treeIcons: {leaf:'ui-icon-document-b'},
caption: "jqGrid Demos",
//autowidth: true,
rowNum: 10000,
//ExpandColClick: true,
jsonReader: {
repeatitems: false,
root: "response"
},
onSelectRow: function(id){
if(id && id!==lastsel){
grid.jqGrid('restoreRow',lastsel);
grid.jqGrid('editRow',id,true);
lastsel=id;
}
}
});
});
-----------------------------------------------------
转载请注明来源此处
原地址:#