博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
EasyUi subgrid 三级列表实现
阅读量:6419 次
发布时间:2019-06-23

本文共 4397 字,大约阅读时间需要 14 分钟。

hot3.png

工作中用到了EasyUi的subgrid,需做三级列表,由于easyui的demo只支持到两级,故三级扩展如下(备注:最新easyui1.4.1中,提供一个新的Nested SubGrid,本身api就支持多级列表,大家若觉得subgrid实现麻烦且业务不复杂,可试下用Nested SubGrid):

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<html>

<head>

    <title>Subgrid 3 level List</title>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <link rel="stylesheet" type="text/css" href="../jquery-easyui-1.4.1/themes/default/easyui.css">

    <link rel="stylesheet" type="text/css" href="../jquery-easyui-1.4.1/themes/icon.css">

    <link rel="stylesheet" type="text/css" href="../jquery-easyui-1.4.1/demo/demo.css">

    <script type="text/javascript" src="../js/jquery-1.6.4.js"></script>

    <script type="text/javascript" src="../jquery-easyui-1.4.1/jquery.easyui.min.js"></script>

    <script type="text/javascript" src="../js/datagrid-detailview.js"></script><!--该js必须引用-->

</head>

<body>

    <table id="dg" style="width:1280px;height:500px" > </table>

     <script type="text/javascript">

     var fatherinternalTimer;

      var soninternalTimer;  

     $(function(){    

       //加载grid

       $('#dg').datagrid({

                url: "${pageContext.request.contextPath}/yeyeurl.json",

                title: "demo",

                height: 525,

                singleSelect: false,

                checkOnSelect: true,

                selectOnCheck: true,

                fitColumns: false,

                                view: detailview,

                toolbar: "#tb",//这样展示出来的时候比较灵活

                rownumbers:true,//行号

                pagination:true,//分页

                columns:[[

                      {field:'ck1',width:30,checkbox:true},

                  {field:'action',title:'操作',width:80,align:'center',

                   formatter:function(value,rowData,rowindex){

                   var viewMenu = '<a href="javascript:;" οnclick="alert('view grid');"></a>';

                   return viewMenu;

                                      }  

                

                   },

                  {field:'id',title:'爷爷级ID',width:80}

                ]],

               view: detailview, 

           detailFormatter:function(index,yeyerow){ 

               return '<div style="padding:0px"><table class="'+yeyerow.id+'ddv"></table></div>';

           },

           onExpandRow: function(index,yeyerow){

               $('.'+yeyerow.id+'ddv').datagrid({

                     url:'${pageContext.request.contextPath}/babaurl.json?yeyeid='+yeyerow.id,

                     singleSelect:true,

                     fitColumns: true,

                     rownumbers:false,

                     loadMsg:'加载中...',

                     height:'auto',

                     columns:[[

                         {field:'id',title:'爸爸级ID',width:80}

                         ]],

                   onResize:function(){

                   $.each($('#dg').datagrid('getRows'), function (i, row) { 

                      $('#dg').datagrid('fixRowHeight', i); 

                           }); 

                   $('#dg').datagrid('fixDetailRowHeight',index);

                   },

                   onLoadSuccess:function(){ 

                   clearTimeout(fatherinternalTimer);

                   fatherinternalTimer =

                    setInterval(function(){ 

                    $.each($('#dg').datagrid('getRows'), function (i, row) { 

                                                   $('#dg').datagrid('fixRowHeight', i); 

                                               }); 

                                             $('#dg').datagrid('fixDetailRowHeight',index);

                                            },10); 

                                       },

                    view: detailview,

                    detailFormatter:function(index_child,babarow){ 

                    return '<div style="padding:0px"><table class="'+babarow.id+'ddvv"></table></div>';

                    },

                    onExpandRow: function(index_child,babarow){

                    $('.'+babarow.id+'ddvv').datagrid({

                    url:'${pageContext.request.contextPath}/erziurl?babaid='+babarow.id, 

                    singleSelect:true,

                    fitColumns: false,

                    rownumbers:false,

                    loadMsg:'加载中...',

                    height:'auto',

                    columns:[[ 

                                    {field:'id',title:'儿子级ID',width:80}

                    ]],

                    onResize: function(){

                    $.each($('.'+yeyerow.id+'ddv').datagrid('getRows'), function (i, row) { 

                      $('.'+yeyerow.id+'ddv').datagrid('fixRowHeight', i); 

                       }); 

                       $.each($('#dg').datagrid('getRows'), function (i, row) { 

                       $('#dg').datagrid('fixRowHeight', i); 

                       $('#dg').datagrid('fixDetailRowHeight', i); 

                       }); 

                    

                     //父表格改变大小 

                       $('.'+yeyerow.id+'ddv').datagrid('fixDetailRowHeight', index_child); 

                     //爷爷表格改变大小

                       $('#dg').datagrid('fixDetailRowHeight', index);

                                   },

                    

                    onLoadSuccess: function(){

                    $.each($('.'+yeyerow.id+'ddv').datagrid('getRows'), function (i, row) { 

                    $('.'+yeyerow.id+'ddv').datagrid('fixRowHeight', i); 

                       }); 

                       $.each($('#dg').datagrid('getRows'), function (i, row) { 

                       $('#dg').datagrid('fixRowHeight', i); 

                       }); 

                       $('.'+yeyerow.id+'ddv').datagrid('fixDetailRowHeight', index_child); 

                       $('#dg').datagrid('fixDetailRowHeight', index); 

                    //延迟执行一次后,点击缩进的话不能恢复原形,所以不用延迟函数,而是使用间隔函数

                    clearTimeout(soninternalTimer);

                    soninternalTimer =

                    setInterval(function(){ 

                    $.each($('.'+yeyerow.id+'ddv').datagrid('getRows'), function (i, row) { 

                    $('.'+yeyerow.id+'ddv').datagrid('fixRowHeight', i); 

                                               }); 

                                               $.each($('#dg').datagrid('getRows'), function (i, row) { 

                                                   $('#dg').datagrid('fixRowHeight', i); 

                                                   $('#dg').datagrid('fixDetailRowHeight', i); 

                                               }); 

                                               $('.'+yeyerow.id+'ddv').datagrid('fixDetailRowHeight', index_child); 

                                               $('#dg').datagrid('fixDetailRowHeight', index); 

                                                },5);  

                                       }

                                  });

            }

               });

           }

       });

     });

    </script>

</body>

</html>

转载于:https://my.oschina.net/softwarechina/blog/299811

你可能感兴趣的文章
小黑小波比.清空<div>标签内容
查看>>
Java中的ExceptionInInitializerError异常及解决方法
查看>>
Spring 注入bean时的初始化和销毁操作
查看>>
java线程同步原理(lock,synchronized)
查看>>
MyEclipse中使用Hql编辑器找不到Hibernate.cfg.xml文件解决方法
查看>>
yRadio以及其它
查看>>
第四节 对象和类
查看>>
闪迪(SanDisk)U盘防伪查询(官方网站)
查看>>
Android onMeasure方法介绍
查看>>
无锁数据结构
查看>>
MySQL的变量查看和设置
查看>>
android onNewIntent
查看>>
XML特殊符号
查看>>
kaptcha可配置项
查看>>
JavaMail邮箱验证用户注册
查看>>
系统时间——ntpd
查看>>
反射实现AOP动态代理模式(Spring AOP实现原理)
查看>>
Http协议与缓存
查看>>
监测超过特定内存阀值进程并结束
查看>>
Linux Centos 查询信息
查看>>