首页 > 其他分享 >Layui 之TreeTable(树形数据表格),适用于权限、部门等

Layui 之TreeTable(树形数据表格),适用于权限、部门等

时间:2022-10-21 14:00:09浏览次数:84  
标签:__ open Layui TreeTable 树形 entered data id delete

TreeTable.js下载

链接:​​https://pan.baidu.com/s/1lLBge_4MSSViLztwTnPfkA ​​提取码:whj3

一、效果图

Layui 之TreeTable(树形数据表格),适用于权限、部门等_数据

 

二、前端代码

{include file='common/header'}
<div class="layui-fluid">
<div class="layui-row layui-col-space15">
<div class="layui-col-md12">
<div class="layui-card layui-form">
<div class="layui-card-header">{:__('Query conditions')}</div>
<div class="layui-card-body layui-row layui-col-space15">
<div class="layui-col-md12">
<div class="layui-btn-group demoTable">
{if $check->checkPrivilege('department/add')}<button class="layui-btn " data-type="add">
<i class="layui-icon layui-icon-addition"></i>{:__('Add')}
</button>{/if}
{if $check->checkPrivilege('department/delete_op')} <button class="layui-btn layui-btn-danger" data-type="delAll"><i
class="layui-icon layui-icon-delete"></i>{:__('Delete all')}
</button>{/if}
</div>
</div>
</div>
</div>
</div>
<div class="layui-col-md12">
<div class="layui-card layui-form">
<div class="layui-card-body">
<table class="layui-hide" id="app" lay-filter="app"></table>
</div>
</div>
</div>
</div>
</div>
<script type="text/html" id="operate">
{if $check->checkPrivilege('department/child')}<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="child">{:__('Add child')}</a>{/if}
{if $check->checkPrivilege('department/edit')}<a class="layui-btn layui-btn-xs" lay-event="edit">{:__('Edit')}</a>{/if}
{if $check->checkPrivilege('department/delete_op')}<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">{:__('Delete')}</a>{/if}
</script>
{include file='common/footer'}
<script>
layui.config({
base : '/static/admin/layui/lay/modules/'
}).extend({
treeTable : 'treeTable'
});
var table = null;
layui.use(['treeTable', 'form'], function () {
table = layui.treeTable;
table.render({
id: "app",
elem: '#app',
url: "{:url('department/lst')}",
tree: {
iconIndex: 1,
isPidData: true,
idName: 'id',//父ID
pidName: 'parent_id',//子ID
openName: 'open',// 是否默认展开的字段名
//public bool open { get; set; }open字段是bool类型
},
cols: [[
{field: 'id', title: 'ID', width: 100}
, {
field: 'name', title: "{:__('Department name')}"
}
, {field: 'update_entered', title: "{:__('Update time')}"}
, {field: 'date_entered', title: "{:__('Create time')}"}
, {fixed: 'right', title: "{:__('Operate')}", toolbar: '#operate', width: 180}
]],
page: false,
cellMinWidth: 80,
// toolbar: '#toolbar',
// defaultToolbar: ['filter', 'exports', 'print']
});
table.on('tool(app)', function (obj) {
let data = obj.data, id = data.id;
switch (obj.event) {
case 'child':
layer.open({
type: 2,
title: "{:__('Add %s', __('App name'))}",
area: ["600px", "400px"],
content: "{:url('department/add')}?id="+id,
maxmin: true,
});
break;
case 'edit':
layer.open({
type: 2,
title: "{:__('Edit %s', __('App name'))}",
area: ["600px", "400px"],
content: "{:url('department/edit')}?id="+id,
maxmin: true,
});
break;
case 'delete':
delete_op(id, "{:__('Are you sure you want to delete this item?')}");
break;
}
});

var active = {
add: function () {
layer.open({
type: 2,
title: "{:__('Add %s', __('App name'))}",
area: ["600px", "550px"],
content: "{:url('department/add')}",
maxmin: true,
});
},
delAll: function () {
var checkStatus = table.checkStatus('app'),
data = checkStatus.data, ids="";

if (data.length == 0) {
layer.msg("{:__('Please select the item to delete')}", {
icon: 5,
shift: 6
});
return false;
}
for (let i = 0; i < data.length; i++) {
if (i == data.length - 1) {
ids += data[i].id;
}else {
ids += data[i].id + ",";
}
}
delete_op(ids, "{:__('Are you sure you want to delete this item?')}");
}
};

$('.layui-btn').on('click', function() {
var type = $(this).data('type');
active[type] && active[type].call(this);
});

function delete_op(id, msg) {
layer.confirm(msg, function (index) {
$.ajax({
url: "{:url('department/delete_op')}",
data: {id: id},
type: "post",
success: function (data) {
if (data.code == 1) {
layer.msg(data.msg, {
icon: 1
});
location.reload(true);
} else {
layer.msg(data.msg, {
icon: 5,
shift: 6
});
}
layer.close(index);
}
});
layer.close(index);
});
}
});
</script>

三、后台数据

{
"code": 0,
"msg": "获取成功",
"time": 1659322274,
"data": [{
"id": 1,
"name": "test",
"parent_id": 0,
"date_entered": null,
"update_entered": null,
"open": true
}, {
"id": 2,
"name": "h",
"parent_id": 1,
"date_entered": null,
"update_entered": null,
"open": true
}, {
"id": 3,
"name": "222",
"parent_id": 1,
"date_entered": null,
"update_entered": null,
"open": true
}, {
"id": 4,
"name": "哈哈",
"parent_id": 0,
"date_entered": "2022-08-01 10:28:38",
"update_entered": "2022-08-01 10:28:38",
"open": true
}, {
"id": 5,
"name": "好",
"parent_id": 4,
"date_entered": "2022-08-01 10:28:53",
"update_entered": "2022-08-01 10:35:19",
"open": true
}],
"count": 5
}

 



标签:__,open,Layui,TreeTable,树形,entered,data,id,delete
From: https://blog.51cto.com/u_15309652/5782625

相关文章

  • 2020CCPC威海 C Rencontre(树形DP,期望)
    题意:有3个人,每个人有一些待选位置。就是当确定三个人确定位置u1,u2,u3后,需要找到一个位置v到三个位置的距离之和最小,现在给出u1,u2,u3的待选取值,问距离......
  • HDU2376——Average distance(思维+树形DP)
    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2376原文:https://www.codenong.com/cs109682980/题意:给定一棵树,有边权,求树上任意两点之间距离的和的平均值。思路......
  • Layui+treetable树实现 权限菜单多选单选
    HTML代码 所需文件我也一并上传链接:https://pan.baidu.com/s/1bAB2Pf5Dp5BDqEsMyrmWow?pwd=6666提取码:6666  效果图  需要注意的是这个不用多维数组但是要......
  • nginx本地配置web项目-layui
    nginx安装配置以及配置本地web项目nginx下载和安装介绍nginx(enginex)是一个高性能的HTTP和反向代理web服务器,其他的介绍自己百度去看下载https://nginx.org/en/downl......
  • HDU-1054 Strategic Game(树形DP)
    StrategicGameTimeLimit:20000/10000ms(Java/Other)MemoryLimit:65536/32768K(Java/Other)TotalSubmission(s):17AcceptedSubmission(s):11Font:......
  • HDU-1520 Anniversary party(树形DP)
    AnniversarypartyTimeLimit:2000/1000MS(Java/Others)MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):7566AcceptedSubmission(s):3321P......
  • C# winform treeview GDI+流程连线 流程图 树形流程图
    C#winformtreeviewGDI+流程连线流程图树形流程图 TreeView_Paint的方法呈现效果,具体如下1.点击连线按钮开始准备连线2.点击第一个连线的起始节点3.再点击第二个......
  • layui文件上传重复问题
    upload.render({elem:'#add_ppts',url:localStorage.getItem('url')+'/upload/upload/ppt_upload',accept:'video'//视频......
  • AcWing 4706 -- 树形DP/DFS
    题目描述4706.最短路程思路dfs代码#include<iostream>#include<cstring>#include<algorithm>#include<vector>usingnamespacestd;constintN=100......
  • 2020CCPC秦皇岛-K. Kingdom's Power(树形DP + 贪心)
    题意给出一个有n个节点的有根树,1为根节点,根节点有无穷多个兵,每一秒可以让任意一个兵向任意一个地方移动一步,兵所到的点被占领,问最少需要经过多少秒,才能将所有的点都占领......