
正文
JEECG树(TreeGrid)字段的扩展
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
转载:https://blog.csdn.net/huangzirong822/article/details/38400817
之前使用jeecg集成框架做过一个项目 这里说说框架中树(tree)字段的扩展,在jeecg集成框架中,树列字段默认只能显示两列,如下图所示: 通常情况下前后台代码格式如下所示 前台代码获取(部分) <t:datagrid name="departList" title="部门列表" actionUrl="departController.do?departgrid" treegrid="true" idField="departid" pagination="false" onClick="queryUsersByRowData">
<t:dgCol title="编号" field="id" treefield="id" hidden="false"></t:dgCol>
<t:dgCol title="部门名称" field="departname" treefield="text" ></t:dgCol>
<t:dgCol title="职能描述" field="description" treefield="src"></t:dgCol>
<t:dgCol title="操作" field="opt"></t:dgCol>
<t:dgDelOpt url="departController.do?del&id={id}" title="删除"></t:dgDelOpt>
<t:dgFunOpt funname="queryUsersByDepart(id)" title="查看成员"></t:dgFunOpt>
</t:datagrid> 后台代码(部分) /**
* 部门列表,树形展示
* @param request
* @param response
* @param treegrid
* @return
*/
@RequestMapping(params = "departgrid")
@ResponseBody
public List<TreeGrid> departgrid(TSDepart tSDepart,HttpServletRequest request, HttpServletResponse response, TreeGrid treegrid) {
CriteriaQuery cq = new CriteriaQuery(TSDepart.class);
if("yes".equals(request.getParameter("isSearch"))){
treegrid.setId(null);
tSDepart.setId(null);
}
if(null != tSDepart.getDepartname()){
org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, tSDepart);
}
if (treegrid.getId() != null) {
cq.eq("TSPDepart.id", Integer.parseInt(treegrid.getId()));
}
if (treegrid.getId() == null) {
cq.isNull("TSPDepart.id");
}
cq.add();
List<TreeGrid> departList =null;
departList = systemService.getListByCriteriaQuery(cq, false);
if(departList.size() == && tSDepart.getDepartname() != null){
cq = new CriteriaQuery(TSDepart.class);
TSDepart parDepart = new TSDepart();
tSDepart.setTSPDepart(parDepart);
org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, tSDepart);
departList = systemService.getListByCriteriaQuery(cq, false);
}
List<TreeGrid> treeGrids = new ArrayList<TreeGrid>();
TreeGridModel treeGridModel = new TreeGridModel();
treeGridModel.setTextField("departname");
treeGridModel.setParentText("TSPDepart_departname");
treeGridModel.setParentId("TSPDepart_id");
treeGridModel.setSrc("description");
treeGridModel.setIdField("id");
treeGridModel.setChildList("TSDeparts");
treeGrids = systemService.treegrid(departList, treeGridModel);
return treeGrids;
} 以上是没有是没有扩展树字段的实例,以下是扩展的实例
!扩展方法
其实扩展方法很简单,因为 作者已经帮我们留了扩展的方法了。捕捉树列表响应的数据如下(部分响应数据): [
{
"operations": null,
"note": null,
"order": null,
"src": "",
"parentId": "",
"parentText": "中联总部",
"id": "",
"state": "closed",
"attributes": null,
"text": "中联总部",
"code": null
},
{
"operations": null,
"note": null,
"order": null,
"src": "",
"parentId": "",
"parentText": "混凝土机械国际管理公司",
"id": "",
"state": "closed",
"attributes": null,
"text": "混凝土机械国际管理公司",
"code": null
},
{
"operations": null,
"note": null,
"order": null,
"src": "",
"parentId": "",
"parentText": "工程起重机公司",
"id": "",
"state": "closed",
"attributes": null,
"text": "工程起重机公司",
"code": null
},
{
"operations": null,
"note": null,
"order": null,
"src": "",
"parentId": "",
"parentText": "建筑起重机公司",
"id": "",
"state": "closed",
"attributes": null,
"text": "建筑起重机公司",
"code": null
}
] 以上数据可以看出在每条返回的数据中存在一个attribute字段,但都是空值。其实这个就是可以扩展的字段attribute是一个HashMap 即扩展树字段的方法原理就是后台添加attribute并把需要在前台显示的值存进去,前台取attribute的值。代码如下 后台代码(因为没有扩展上面机构tree代码,我挑选了其他树扩展的代码) Map<String , String> map;
for (int i = ; i < treeGrids.size(); i++) {
map = new HashMap<String, String>();
map.put("description", assetDepreciationList.get(i).getDescription());
treeGrids.get(i).setAttributes(map);
}
把需要扩展显示的字段put进去,上面我增加了一个显示字段,如果有多个同样put多个进去。 前台jsp代码 <t:datagrid name="assetDepreciationList" title="折旧类型管理" actionUrl="assetDepreciationController.do?assetDepreciationGrid" idField="id" treegrid="true" pagination="false" fit="true">
<t:dgCol title="编号" field="id" treefield="id" hidden="false"></t:dgCol>
<t:dgCol title="折旧计算方法" field="depreciationWay" treefield="text"></t:dgCol>
<t:dgCol title="折算周期" field="depreciationCycle" treefield="src"></t:dgCol>
<t:dgCol title="方法描述" field="attributes.description" treefield="attributes.description" extendParams="formatter:function(value, rec, index){return rec.attributes.description};" width=""></t:dgCol>
<t:dgCol title="操作" field="opt" width=""></t:dgCol>
<t:dgDelOpt title="删除" url="assetDepreciationController.do?del&id={id}"/>
<t:dgToolBar title="录入" icon="icon-add" url="assetDepreciationController.do?addorupdate" funname="add"></t:dgToolBar>
<t:dgToolBar title="编辑" icon="icon-edit" url="assetDepreciationController.do?addorupdate" funname="update"></t:dgToolBar>
<t:dgToolBar title="查看" icon="icon-search" url="assetDepreciationController.do?addorupdate" funname="detail"></t:dgToolBar>
</t:datagrid> 方法描述即为扩展的显示列(写法如下)
写法一 <t:dgCol title="方法描述" field="attributes.description" treefield="attributes.description" extendParams="formatter:function(value, rec, index){return rec.attributes.description};" width=""></t:dgCol> 或者是将js方法写出来
写法二 <t:dgCol title="方法描述" field="attributes.description" treefield="attributes.description" extendParams="formatter:getDescription;" width=""></t:dgCol>
function getDescription(value, rec, index) {
return rec.attributes.descripition;
}
以上就是jeecg中树的列显示字段扩展,如果有多个需要扩展就根据以上格式编写多个即可。 ---------------------
版权声明:本文为CSDN博主「Zero-荣子」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/huangzirong822/article/details/38400817






