layui点击可以伸缩的数据表格实例(表格行伸缩)

layui制作可以伸缩的数据表格;

具体表现为以下
效果图:
在这里插入图片描述

以下提供js代码与json代码

js代码:

以下代码为自动渲染表格;需要注意的是tree属性和col属性

tree: tree中的idNamepidName分别对应json数据中的本身唯一id和父级唯一id;
col: col中需要注意嵌套的对象和数组以及模板 ;下面的示例演示了layui特性的一些用法;大家可以根据项目实际情况来选择

// 渲染表格
            var insTb = treeTable.render({
                elem: '#LAY_table_user',
                url: 'json/menus.json',
                height: 'full-200',
                tree: {
                    iconIndex: 0,
                    isPidData: true,
                    idName: 'authorityId',
                    pidName: 'parentId'
                },
                cols: [
                    [
                        {title: '管理指标体系', colspan: 18},
                    ],
                    [
                        {field: 'authorityName', title: '对标指标', minWidth: 165},
                        {
                            title: '菜单图标', align: 'center', hide: true,
                            templet: '<p><i class="layui-icon {{d.menuIcon}}"></i></p>'
                        },
                        {field: 'authority', title: '数据单位'},
                        {title: '数据精度', templet: '<p>{{d.isMenu?"菜单":"按钮"}}</p>', align: 'center', width: 60},
                        {
                            title: '报送周期', templet: function (d) {
                                return util.toDateString(d.createTime);
                            }
                        },
                        {field: 'authority', title: '权重'},
                        {field: 'authority', title: '本期值'},
                        {field: 'authority', title: '累计值'},
                        {field: 'authority', title: '累计分子值'},
                        {field: 'authority', title: '累计分母值'},
                        {field: 'authority', title: '审核累计值'},
                        {field: 'authority', title: '段位'},
                        {field: 'authority', title: '排名'},
                        {field: 'authority', title: '最优值'},
                        {field: 'authority', title: '最差值'},
                        {field: 'authority', title: '平均值'}
                    ],

                ],
                style: 'margin-top:0;'
            });

menus.json数据

这个json数据里面需要layui需要读取用到authorityId,menuIcon,isMenu,open,parentId等字段;

authorityId : 当前数据id
parentId :当前指向父级id;可以被识别包含
menuIcon : 折叠展开的图标按钮
isMenu :是否属于菜单下;
open : 默认是否展示

{
  "code": 0,
  "msg": "",
  "count": 19,
  "data": [
    {
      "authorityId": 1,
      "authorityName": "国网湖南省电力公司长沙供电分公司",
      "orderNumber": 1,
      "menuUrl": null,
      "menuIcon": "layui-icon-set",
      "createTime": "2018/06/29 11:05:41",
      "authority": null,
      "checked": 0,
      "updateTime": "2018/07/13 09:13:42",
      "isMenu": 0,
      "parentId": -1,
      "open": true
    },
    {
      "authorityId": 2,
      "authorityName": "安监部",
      "orderNumber": 2,
      "menuUrl": "system/user",
      "menuIcon": null,
      "createTime": "2018/06/29 11:05:41",
      "authority": null,
      "checked": 0,
      "updateTime": "2018/07/13 09:13:42",
      "isMenu": 0,
      "parentId": 1,
      "open": true
    },
    {
      "authorityId": 3,
      "authorityName": "人身伤亡",
      "orderNumber": 3,
      "menuUrl": "",
      "menuIcon": "",
      "createTime": "2018/07/21 13:54:16",
      "authority": "user:view",
      "checked": 0,
      "updateTime": "2018/07/21 13:54:16",
      "isMenu": 1,
      "parentId": 2,
      "open": true
    },
    {
      "authorityId": 4,
      "authorityName": "电网和设备事件数",
      "orderNumber": 4,
      "menuUrl": null,
      "menuIcon": null,
      "createTime": "2018/06/29 11:05:41",
      "authority": "user:add",
      "checked": 0,
      "updateTime": "2018/07/13 09:13:42",
      "isMenu": 1,
      "parentId": 2,
      "open": true
    },
    {
      "authorityId": 5,
      "authorityName": "误操作事件",
      "orderNumber": 5,
      "menuUrl": null,
      "menuIcon": null,
      "createTime": "2018/06/29 11:05:41",
      "authority": "user:edit",
      "checked": 0,
      "updateTime": "2018/07/13 09:13:42",
      "isMenu": 1,
      "parentId": 2,
      "open": true
    },
    {
      "authorityId": 6,
      "authorityName": "信息和网络安全事件",
      "orderNumber": 6,
      "menuUrl": null,
      "menuIcon": null,
      "createTime": "2018/06/29 11:05:41",
      "authority": "user:delete",
      "checked": 0,
      "updateTime": "2018/07/13 09:13:42",
      "isMenu": 1,
      "parentId": 2,
      "open": true
    }
  ]
}

自己看了一些示例慢慢摸索出来的,在此分享给大家;如发现有错误请各位指正!加油加油加油!!

以上。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值