这篇文章主要为大家详细介绍了java easyui树形表格treegrid的实现代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
自己搞了一下午,终于用java实现了数据网格。记录一下实现的代码。(ps:此处的easyui是1.5版本,楼主只贴了核心的代码)
实现图
jsp页面
<head>
//权限列表
$( document ).ready(function(){
var parentid = 0;
$('#tt').treegrid({
url:'queryprivilege.action?parentid='+parentid,
idfield:'id',
treefield:'recordstatus',
columns:[[
{title:'id',field:'id',width:180},
{field:'recordstatus',title:'recordstatus',width:180} ,
{field:'privilegeoperation',title:'privilegeoperation',width:180}
]],
onbeforeexpand:function(row){
//动态设置展开查询的url
$(this).treegrid('options').url = 'queryprivilege.action?parentid='+row.id;
}
});
})
</script>
</head>
<body>
<table id="tt" style="width:600px;height:400px"></table>
</body>
action层代码
//输出
public printwriter out()throws ioexception{
httpservletresponse response=servletactioncontext.getresponse();
response.setcontenttype("text/html");
response.setcontenttype("text/plain; charset=utf-8");
printwriter out= response.getwriter();
return out;
}
public string queryprivilege() throws ioexception{
returnpd="ok";
jsonarray array =new jsonarray();
array = privilegeservice.getmenu(parentid);
string str=array.tostring();
out().print(str);
out().flush();
out().close();
return returnpd;
}
service层接口代码
jsonarray getmenu(int parentid);
serviceimpl层代码(实现service层)
@override
public jsonarray getmenu(int parentid) {
// todo auto-generated method stub
return (jsonarray)privilegedao.getmenu(parentid);
}
dao层代码
jsonarray getmenu(int parentid);
daoimpl层代码(实现dao层)
@override
public jsonarray getmenu(int parentid) {
// todo auto-generated method stub
string hql="";
jsonarray array=new jsonarray();
hql="from privilege p where p.parentid = "+parentid;
for(privilege privilege:(list<privilege>)(getsession().createquery(hql).list())){
jsonobject jo=new jsonobject();
jo.put("id", privilege.getid());
jo.put("recordstatus", privilege.getrecordstatus());
jo.put("parendid",privilege.getparentid());
if(privilege.getparentid()==0){
jo.put("state","closed");
}
else{
jo.put("state","open");
system.out.println(parentid);
}
array.add(jo);
}
return array;
}
数据库一览
以上就是详解java easyui树形表格treegrid的示例代码(图)的详细内容。