t:datagrid中的treegrid树形的多表组装

症状:树形图每一层所来自不同表。

处方:

业务思想:首先明确treegrid是懒加载模式,单击展开时,再重新去后台找出单击的子列表数据。主要代码解决问题在于,是否存在下级的页面上的icon问题。由于是直接测试边使用,并未先写了测试例子,所以直接把代码复制了。仅把关键常量改了改。

jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>
<div id="main_list" class="easyui-layout" fit="true">
 <div region="center" style="padding:0px;border:0px">
 <t:datagrid name="projectListToTree" title="工程项目结构" actionUrl="AController.do?datagridProjectListToTree" treegrid="true" idField="id" pagination="false">
  <t:dgCol title="编号" field="id" treefield="id" hidden="false" />
  <t:dgCol title="名称" field="name" treefield="text" />
  <t:dgCol title="操作" field="opt" width="100"></t:dgCol>
  <t:dgFunOpt funname="addCheck(id)" title="分部工程鉴定表" exp="id#eq#4_id"></t:dgFunOpt>
  <t:dgFunOpt funname="addCheck(id)" title="鉴定表" ></t:dgFunOpt>
 </t:datagrid>
 </div>
</div>

 <script type="text/javascript">
 $("#projectListToTree").treegrid({  
       onExpand : function(node){
        //$('#main_list').layout('expand','east'); 
        if(node.id[0]==1){
            //$('#commodity-panel').panel("refresh", "AController.do?constructListCheckUp&projectId="+node.id.split("_")[1]+"&checkType=1");
        }else if(node.id[0]==2){
            //$('#commodity-panel').panel("refresh", "AContractCheckupController.do?gsProjectContractCheckup&contractId="+node.id.split("_")[1]);
        }else if(node.id[0]==3){
            //$('#commodity-panel').panel("refresh", "AController.do?gsProjectWorkCheckup&workId="+node.id.split("_")[1]);
        }else{
            //$('#commodity-panel').panel("refresh", "AController.do?workSubList&workId="+node.id.split("_")[1]);
        }
      },
      onClickRow:function(node){
         // $('#main_list').layout('expand','east'); 
         // $('#commodity-panel').panel("refresh", "AController.do?constructList&projectId="+node.id.split("_")[1]+"&checkType=1");
         // $('#commodity-panel').panel('refresh', 'AController.do?projectBussList');
      }
 }); 
 
 function addCheck(id){
    createAddCheck('鉴定数据', 'AController.do?addItemRecordCheck&id='+id);
}


/**
 * 创建添加或编辑窗口
 * 
 * @param title
 * @param addurl
 * @param saveurl
 */
function createAddCheck(title, addurl,width,height) {
    width = width?width:800;
    height = height?height:350;
    if(width=="100%" || height=="100%"){
        width = document.body.offsetWidth;
        height =document.body.offsetHeight-100;
    }
    if(typeof(windowapi) == 'undefined'){
        
        $.dialog({
            content: 'url:'+addurl,
            lock : true,
            width:width,
            height:height,
            title:title,
            opacity : 0.3,
            cache:false,
            button : [{
            name : '确定',
            callback : function() {
                iframe = this.iframe.contentWindow;
                saveObj();
                //获取页面的值
                var orgName = $('#name', iframe.document).val();
                if(orgName != ''){
                   $(this).dialog("close");
                }else{
                   return false;
                }
                
             },
            focus : true
        }, {
            name : '关闭',
            callback : function() {
               $(this).dialog("close"); 
            }
         }]
      });
    }else{
        W.$.dialog({
            content: 'url:'+addurl,
            lock : true,
            width:width,
            height:height,
            parent:windowapi,
            title:title,
            opacity : 0.3,
            cache:false,
            button : [{
              name : '鉴定数据',
              callback : function() {
                iframe = this.iframe.contentWindow;
                saveObj();
                //获取页面的值
                var orgName = $('#name', iframe.document).val();
                if(orgName != ''){
                    $(this).dialog("close"); 
                }else{
                    return false;
                }
                
             },
            focus : true
        }, {
            name : '关闭',
            callback : function() {
                 $(this).dialog("close"); 
            }
         }]
        });
    }
    
}
/**
 * 执行保存
 * 
 * @param url
 * @param gridname
 */
function saveObj() {
    $('#btn_sub', iframe.document).click();
}
 </script>
<script src = "webpage/com/gs/project/projectListToTree.js"></script>

java::controller

/**
     * 工程作业鉴定,树形展示
     * @param request
     * @param response
     * @param treegrid
     * @return
     */
    @RequestMapping(params = "datagridProjectListToTree")
    @ResponseBody
    public  List<TreeGrid>  datagridProjectListToTree(/*PtypeEntity*/TSDepart tSDepart,HttpServletRequest request, HttpServletResponse response, TreeGrid treegrid) {
        List<TreeGrid> treeGrids = new ArrayList<TreeGrid>();
     //模型 TreeGridModel treeGridModel
= new TreeGridModel(); treeGridModel.setTextField("departname"); treeGridModel.setSrc("code"); treeGridModel.setOrder("latitude"); treeGridModel.setIdField("id"); treeGridModel.setChildList("TSDeparts"); StringBuffer str = new StringBuffer(); str.append(" SELECT ID,PROJECT_NAME FROM GS_PROJECT_BUSS WHERE DELFLAG=0 "); if(treegrid.getId() != null){ } List<Record> rlist = Db.use("gl").find(str.toString()); List<TSDepart> tdp = new ArrayList<TSDepart>(); List<Map<String, Object>> list2 = new ArrayList<Map<String,Object>>(); if(treegrid.getId() != null){ // id:1_id 2_id 3_id 4_id ::分别为项目工程,合同段,单位工程,分布工程 String[] ids = treegrid.getId().split("_"); if(ids[0].equals("1")){// 项目工程下的合同段 String contract_Sql = "SELECT CONTRACT_ID,CONTRACT_NAME FROM GS_PROJECT_CONTRACT_BUSS WHERE DELFLAG=0 AND PROJECT_BUSS_ID='"+ids[1]+"'"; rlist = Db.use("gl").find(contract_Sql); for (int i = 0; i < rlist.size(); i++) { TSDepart tSDeparts1 = new TSDepart(); tSDeparts1.setId("2_"+rlist.get(i).get("CONTRACT_ID").toString()); tSDeparts1.setDepartname(rlist.get(i).get("CONTRACT_NAME").toString()); tdp.add(tSDeparts1); } list2 = new ArrayList<Map<String,Object>>(); for (int i = 0; i < rlist.size(); i++) { Map<String, Object> map2 = new HashMap<String, Object>(); if(StringUtil.isNotEmpty(rlist.get(i).getStr("CONTRACT_ID"))){ map2.put("id", "2_"+rlist.get(i).getStr("CONTRACT_ID")); map2.put("name", rlist.get(i).getStr("CONTRACT_NAME")); list2.add(map2); } } }else if(ids[0].equals("2")){// 合同段下的单位工程 String contract_Sql = "SELECT WORK_ID,WORK_NAME FROM GS_PROJECT_WORK_BUSS WHERE DELFLAG=0 AND CONTRACT_ID='"+ids[1]+"'"; rlist = Db.use("gl").find(contract_Sql); for (int i = 0; i < rlist.size(); i++) { TSDepart tSDeparts1 = new TSDepart(); tSDeparts1.setId("3_"+rlist.get(i).get("WORK_ID").toString()); tSDeparts1.setDepartname(rlist.get(i).get("WORK_NAME").toString()); tdp.add(tSDeparts1); } list2 = new ArrayList<Map<String,Object>>(); for (int i = 0; i < rlist.size(); i++) { Map<String, Object> map2 = new HashMap<String, Object>(); if(StringUtil.isNotEmpty(rlist.get(i).getStr("WORK_ID"))){ map2.put("id", "3_"+rlist.get(i).getStr("WORK_ID")); map2.put("name", rlist.get(i).getStr("WORK_NAME")); list2.add(map2); } } }else if(ids[0].equals("3")){// 单位工程下的分部工程 String contract_Sql = "SELECT WORK_SUB_ID,WORKT_SUB_NAME FROM GS_PROJECT_WORK_SUB_BUSS WHERE DELFLAG=0 AND WORK_ID='"+ids[1]+"'"; rlist = Db.use("gl").find(contract_Sql); for (int i = 0; i < rlist.size(); i++) { TSDepart tSDeparts1 = new TSDepart(); tSDeparts1.setId("4_"+rlist.get(i).get("WORK_SUB_ID").toString()); tSDeparts1.setDepartname(rlist.get(i).get("WORKT_SUB_NAME").toString()); tdp.add(tSDeparts1); } } }else{ // 项目工程 for (int i = 0; i < rlist.size(); i++) { TSDepart tSDeparts1 = new TSDepart(); tSDeparts1.setId("1_"+rlist.get(i).get("ID").toString()); tSDeparts1.setDepartname(rlist.get(i).get("PROJECT_NAME").toString()); tdp.add(tSDeparts1); } for (int i = 0; i < rlist.size(); i++) { Map<String, Object> map2 = new HashMap<String, Object>(); if(StringUtil.isNotEmpty(rlist.get(i).getStr("ID"))){ map2.put("id", "1_"+rlist.get(i).getStr("ID")); map2.put("name", rlist.get(i).getStr("PROJECT_NAME")); list2.add(map2); } } } for (int i = 0; i < list2.size(); i++) { for (int j = 0; j < tdp.size(); j++) { if(list2.get(i).get("id").equals(tdp.get(j).getId())){ TSDepart tSDeparts1 = new TSDepart(); tSDeparts1.setId(list2.get(i).get("id").toString()); tSDeparts1.setDepartname(list2.get(i).get("name").toString()); tdp.get(j).getTSDeparts().add(tSDeparts1); } } } treeGrids = systemService.treegrid(tdp, treeGridModel); return treeGrids; }

 

posted @ 2017-05-02 17:17  理解龙儿  阅读(2243)  评论(0编辑  收藏  举报