2017-08-21 08:51:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html lang="en">
|
|
|
|
|
<head>
|
2021-04-22 10:22:45 +08:00
|
|
|
|
<meta charset="utf-8">
|
|
|
|
|
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
|
|
|
|
<title>表格操作 - layui</title>
|
2017-08-21 08:51:13 +08:00
|
|
|
|
|
2021-04-22 10:22:45 +08:00
|
|
|
|
<link rel="stylesheet" href="../src/css/layui.css">
|
2017-08-21 08:51:13 +08:00
|
|
|
|
|
2021-04-22 10:22:45 +08:00
|
|
|
|
<style>
|
|
|
|
|
body{padding: 20px; /*overflow-y: scroll;*/}
|
|
|
|
|
</style>
|
2017-08-21 08:51:13 +08:00
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
|
2021-05-31 08:57:00 +08:00
|
|
|
|
|
2021-05-18 21:20:45 +08:00
|
|
|
|
|
2018-08-18 20:46:14 +08:00
|
|
|
|
<script type="text/html" id="toolbarDemo">
|
|
|
|
|
<div class="layui-btn-container">
|
|
|
|
|
<button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
|
|
|
|
|
<button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
|
2021-03-31 14:07:23 +08:00
|
|
|
|
<button class="layui-btn layui-btn-sm" lay-event="getData">获取当前页所有数据</button>
|
2018-08-18 20:46:14 +08:00
|
|
|
|
<button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
|
2021-04-01 03:21:16 +08:00
|
|
|
|
<button class="layui-btn layui-btn-sm" lay-event="reload">重载(保留初始参数)</button>
|
|
|
|
|
<button class="layui-btn layui-btn-sm" lay-event="reload2">重载(不保留初始参数)</button>
|
2021-04-22 10:22:45 +08:00
|
|
|
|
<button class="layui-btn layui-btn-sm" id="dropdown">
|
|
|
|
|
更多菜单
|
|
|
|
|
<i class="layui-icon layui-icon-down layui-font-12"></i>
|
|
|
|
|
</button>
|
2018-08-18 20:46:14 +08:00
|
|
|
|
</div>
|
|
|
|
|
</script>
|
2017-08-21 08:51:13 +08:00
|
|
|
|
|
2017-11-15 11:57:51 +08:00
|
|
|
|
<table id="test" lay-filter="test"></table>
|
2017-08-21 08:51:13 +08:00
|
|
|
|
|
2021-04-22 10:22:45 +08:00
|
|
|
|
<div id="appendtest"></div>
|
|
|
|
|
<script type="text/html" id="TPL_appendtest">
|
|
|
|
|
<table class="layui-table" lay-data="{url:'json/table/demo2.json', page: true, limit: 6}" lay-filter="appendtest">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th lay-data="{checkbox:true, fixed:'left'}" rowspan="2"></th>
|
|
|
|
|
<th lay-data="{field:'username', width:80}" rowspan="2">联系人</th>
|
|
|
|
|
<th lay-data="{field:'amount', width:120}" rowspan="2">金额</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
</table>
|
|
|
|
|
</script>
|
|
|
|
|
|
2017-11-15 11:57:51 +08:00
|
|
|
|
<script type="text/html" id="barDemo">
|
|
|
|
|
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
|
|
|
|
|
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
|
|
|
|
|
</script>
|
2017-08-21 08:51:13 +08:00
|
|
|
|
|
|
|
|
|
<script type="text/html" id="usernameTpl">
|
2019-09-10 08:37:47 +08:00
|
|
|
|
<a href="" class="layui-table-link">{{d.username || ''}}</a>
|
2017-08-21 08:51:13 +08:00
|
|
|
|
</script>
|
2017-11-15 11:57:51 +08:00
|
|
|
|
|
|
|
|
|
<script type="text/html" id="switchTpl">
|
|
|
|
|
<input type="checkbox" name="yyy" lay-skin="switch" lay-text="女|男">
|
|
|
|
|
</script>
|
|
|
|
|
|
2019-05-31 14:36:29 +08:00
|
|
|
|
<script type="text/html" id="cityTpl">
|
|
|
|
|
<select lay-ignore>
|
|
|
|
|
<option value="浙江杭州">浙江杭州</option>
|
|
|
|
|
<option value="江西南昌">江西南昌</option>
|
|
|
|
|
<option value="湖北武汉">湖北武汉</option>
|
|
|
|
|
</select>
|
|
|
|
|
</script>
|
|
|
|
|
|
2017-11-15 11:57:51 +08:00
|
|
|
|
<script type="text/html" id="checkboxTpl">
|
|
|
|
|
<input type="checkbox" name="" title="锁定" checked>
|
|
|
|
|
</script>
|
|
|
|
|
|
2017-08-21 08:51:13 +08:00
|
|
|
|
<script type="text/html" id="LAY_table_tpl_email">
|
|
|
|
|
<span {{# if(!d.activate){ }}style="color:#999"{{# } }}>{{ d.email }}</span>
|
|
|
|
|
</script>
|
|
|
|
|
|
2018-05-28 18:50:37 +08:00
|
|
|
|
<table id="test2" lay-filter="test2"></table>
|
2017-11-17 14:18:42 +08:00
|
|
|
|
|
2018-08-18 20:46:14 +08:00
|
|
|
|
<div style="display: none1;">
|
2021-04-22 10:22:45 +08:00
|
|
|
|
<table class="layui-table" lay-data="{width:800, height: 300, url:'json/table/demo2.json', page: true, limit: 6}">
|
2018-08-18 20:46:14 +08:00
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th lay-data="{checkbox:true, fixed:'left'}" rowspan="2"></th>
|
|
|
|
|
<th lay-data="{field:'username', width:80}" rowspan="2">联系人</th>
|
|
|
|
|
<th lay-data="{field:'amount', width:120}" rowspan="2">金额</th>
|
|
|
|
|
<th lay-data="{align:'center'}" colspan="3">地址</th>
|
|
|
|
|
<th lay-data="{fixed: 'right', width: 155, align: 'center', toolbar: '#barDemo'}" rowspan="2">操作</th>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<th lay-data="{field:'province', width:130}">省</th>
|
|
|
|
|
<th lay-data="{field:'city', width:130}">市</th>
|
|
|
|
|
<th lay-data="{field:'zone', width:200}">区</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
</table>
|
2017-08-21 08:51:13 +08:00
|
|
|
|
|
2021-04-22 10:22:45 +08:00
|
|
|
|
<table class="layui-table" lay-data="{url:'json/table/demo2.json', page: true, limit: 6}">
|
2018-08-18 20:46:14 +08:00
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th lay-data="{field:'username'}" rowspan="3">联系人</th>
|
2018-09-02 22:41:09 +08:00
|
|
|
|
<th lay-data="{field:'amount', width:120,hide:1}" rowspan="3">金额</th>
|
2018-08-18 20:46:14 +08:00
|
|
|
|
<th lay-data="{align:'center'}" colspan="5">地址1</th>
|
|
|
|
|
<th lay-data="{align:'center'}" colspan="2">地址2</th>
|
|
|
|
|
<th lay-data="{fixed: 'right', width: 120, align: 'center', toolbar: '#barDemo'}" rowspan="3">操作</th>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
2018-09-02 22:41:09 +08:00
|
|
|
|
<th lay-data="{field:'province', width:120,hide:1}" rowspan="2">省</th>
|
|
|
|
|
<th lay-data="{field:'city', width:80,hide:1}" rowspan="2">市</th>
|
2018-08-18 20:46:14 +08:00
|
|
|
|
<th lay-data="{align:'center'}" colspan="2">详细</th>
|
2018-08-28 15:43:16 +08:00
|
|
|
|
<th lay-data="{field:'zone'}" rowspan="2">区</th>
|
2018-08-18 20:46:14 +08:00
|
|
|
|
<th lay-data="{field:'province', width:80}" rowspan="2">省</th>
|
|
|
|
|
<th lay-data="{field:'city', width:80}" rowspan="2">市</th>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
2018-09-02 22:41:09 +08:00
|
|
|
|
<th lay-data="{field:'address', width:120,hide:1}">小区</th>
|
|
|
|
|
<th lay-data="{field:'house', width:150,hide:1}">单元</th>
|
2018-08-18 20:46:14 +08:00
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
</table>
|
2017-09-15 00:50:23 +08:00
|
|
|
|
|
2018-08-18 20:46:14 +08:00
|
|
|
|
<table id="demo"></table>
|
2017-11-15 11:57:51 +08:00
|
|
|
|
|
2017-08-21 08:51:13 +08:00
|
|
|
|
|
2018-08-18 20:46:14 +08:00
|
|
|
|
<div class="layui-btn-group">
|
|
|
|
|
<button class="layui-btn" data-type="parseTable">转化为数据表格</button>
|
|
|
|
|
</div>
|
2017-08-21 08:51:13 +08:00
|
|
|
|
|
2018-08-18 20:46:14 +08:00
|
|
|
|
<table class="layui-table" lay-skin="line" lay-filter="parse-table-demo">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th lay-data="{checkbox:true}"></th>
|
|
|
|
|
<th lay-data="{field:'username', width:200}">昵称</th>
|
|
|
|
|
<th lay-data="{field:'joinTime', width:150}">加入时间</th>
|
|
|
|
|
<th lay-data="{field:'sign'}">签名</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
<tr>
|
|
|
|
|
<td></td>
|
|
|
|
|
<td>贤心1</td>
|
|
|
|
|
<td>2016-11-28</td>
|
|
|
|
|
<td>人生就像是一场修行a</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td></td>
|
|
|
|
|
<td>贤心2</td>
|
|
|
|
|
<td>2016-11-29</td>
|
|
|
|
|
<td>人生就像是一场修行b</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td></td>
|
|
|
|
|
<td>贤心3</td>
|
|
|
|
|
<td>2016-11-30</td>
|
|
|
|
|
<td>人生就像是一场修行c</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
2017-08-21 08:51:13 +08:00
|
|
|
|
|
2018-08-18 20:46:14 +08:00
|
|
|
|
<table class="layui-table" lay-filter="parse-table-demo">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<td rowspan="2" lay-data="{field:'louceng'}">楼层</td>
|
|
|
|
|
<td colspan="2">1单元</td>
|
|
|
|
|
<td colspan="2">2单元</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td lay-data="{field:'men1', width:80}">1门</td>
|
|
|
|
|
<td lay-data="{field:'men2', width:80}">2门</td>
|
|
|
|
|
<td lay-data="{field:'men3', width:80}">1门</td>
|
|
|
|
|
<td lay-data="{field:'men4', width:80}">2门</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>3楼</td>
|
|
|
|
|
<td>301</td>
|
|
|
|
|
<td>302</td>
|
|
|
|
|
<td>301</td>
|
|
|
|
|
<td>302</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>2楼</td>
|
|
|
|
|
<td>201</td>
|
|
|
|
|
<td>202</td>
|
|
|
|
|
<td>201</td>
|
|
|
|
|
<td>202</td>
|
|
|
|
|
</tr>
|
|
|
|
|
<tr>
|
|
|
|
|
<td>1楼</td>
|
|
|
|
|
<td>101</td>
|
|
|
|
|
<td>102</td>
|
|
|
|
|
<td>101</td>
|
|
|
|
|
<td>102</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
2017-11-15 11:57:51 +08:00
|
|
|
|
|
2021-04-01 03:21:16 +08:00
|
|
|
|
<script src="../src/layui.js" src1="//www.layuicdn.com/layui-v2.0.1/layui.js" charset="utf-8"></script>
|
2017-08-21 08:51:13 +08:00
|
|
|
|
<script>
|
2021-04-22 10:22:45 +08:00
|
|
|
|
layui.use(['table', 'dropdown'], function(){
|
|
|
|
|
var table = layui.table
|
|
|
|
|
,$ = layui.$
|
|
|
|
|
,laytpl = layui.laytpl
|
|
|
|
|
,dropdown = layui.dropdown;
|
2017-08-21 08:51:13 +08:00
|
|
|
|
|
2021-04-01 03:21:16 +08:00
|
|
|
|
//全局设定某参数
|
|
|
|
|
table.set({
|
|
|
|
|
where: {
|
2021-05-08 06:31:19 +08:00
|
|
|
|
token: '全局的 token'
|
|
|
|
|
,access: '全局的 access'
|
2021-04-01 03:21:16 +08:00
|
|
|
|
}
|
2021-04-02 06:05:38 +08:00
|
|
|
|
//,defaultToolbar: ['filter']
|
|
|
|
|
,limit: 30
|
|
|
|
|
//,url: 'list'
|
2021-04-01 03:21:16 +08:00
|
|
|
|
//,height: 300
|
|
|
|
|
});
|
|
|
|
|
|
2021-04-22 10:22:45 +08:00
|
|
|
|
$('#appendtest').append($('#TPL_appendtest').html())
|
|
|
|
|
table.init('appendtest');
|
|
|
|
|
|
2017-11-15 11:57:51 +08:00
|
|
|
|
//渲染
|
2018-08-18 20:46:14 +08:00
|
|
|
|
window.ins1 = table.render({
|
2017-11-15 11:57:51 +08:00
|
|
|
|
elem: '#test'
|
2018-09-02 22:41:09 +08:00
|
|
|
|
,height: 400
|
2019-06-06 12:19:43 +08:00
|
|
|
|
//,width: 600
|
2018-08-18 20:46:14 +08:00
|
|
|
|
,title: '用户数据表'
|
2017-11-15 11:57:51 +08:00
|
|
|
|
,url: 'json/table/demo1.json'
|
2018-08-29 01:55:17 +08:00
|
|
|
|
//,size: 'lg'
|
2017-11-16 07:34:22 +08:00
|
|
|
|
,page: {
|
|
|
|
|
|
|
|
|
|
}
|
2019-06-03 07:57:12 +08:00
|
|
|
|
|
2021-03-31 14:07:23 +08:00
|
|
|
|
//,autoSort: false //是否自动排序。如果否,则由服务端排序
|
2018-08-29 23:17:13 +08:00
|
|
|
|
//,loading: false
|
2018-08-18 20:46:14 +08:00
|
|
|
|
,totalRow: true
|
2017-11-17 14:18:42 +08:00
|
|
|
|
,limit: 30
|
2017-11-15 11:57:51 +08:00
|
|
|
|
,toolbar: '#toolbarDemo'
|
2019-09-10 08:37:47 +08:00
|
|
|
|
,defaultToolbar: ['filter', 'exports', 'print', {
|
|
|
|
|
title: '帮助'
|
|
|
|
|
,layEvent: 'LAYTABLE_TIPS'
|
|
|
|
|
,icon: 'layui-icon-tips'
|
|
|
|
|
}]
|
2021-05-31 08:57:00 +08:00
|
|
|
|
,escape: true
|
2017-11-15 11:57:51 +08:00
|
|
|
|
,cols: [[
|
2018-11-01 02:50:21 +08:00
|
|
|
|
{type: 'checkbox', fixed: 'left'}
|
2018-08-18 20:46:14 +08:00
|
|
|
|
,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true, totalRowText: '合计:'}
|
2019-05-31 14:36:29 +08:00
|
|
|
|
,{field:'username', title:'用户名', width:120, edit: 'text', templet: '#usernameTpl'}
|
2019-09-10 08:37:47 +08:00
|
|
|
|
,{field:'email', title:'邮箱', hide: 0, width:150, edit: 'text', templet: function(d){
|
|
|
|
|
return '<em>'+ d.email +'</em>'
|
2018-08-18 20:46:14 +08:00
|
|
|
|
}}
|
2017-11-15 11:57:51 +08:00
|
|
|
|
,{field:'sex', title:'性别', width:80, edit: 'text', sort: true}
|
2021-05-31 08:57:00 +08:00
|
|
|
|
,{field:'city', title:'城市', width:120}
|
2017-11-15 11:57:51 +08:00
|
|
|
|
,{field:'sign', title:'签名'}
|
2021-04-05 23:41:30 +08:00
|
|
|
|
,{field:'experience', title:'积分', width:80, sort: true, totalRow: '{{ d.TOTAL_NUMS }} 分', templet: '<div>{{ d.experience }} 分</div>'}
|
2017-11-15 11:57:51 +08:00
|
|
|
|
,{field:'ip', title:'IP', width:120}
|
2018-08-18 20:46:14 +08:00
|
|
|
|
,{field:'logins', title:'登入次数', width:100, sort: true, totalRow: true}
|
2017-11-15 11:57:51 +08:00
|
|
|
|
,{field:'joinTime', title:'加入时间', width:120}
|
|
|
|
|
,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
|
|
|
|
|
]]
|
2020-11-26 22:12:46 +08:00
|
|
|
|
|
2021-03-31 14:07:23 +08:00
|
|
|
|
,initSort1: {
|
2020-11-26 22:12:46 +08:00
|
|
|
|
field: 'experience' //排序字段,对应 cols 设定的各字段名
|
|
|
|
|
,type: 'desc' //排序方式 asc: 升序、desc: 降序、null: 默认排序
|
|
|
|
|
}
|
2021-04-01 03:21:16 +08:00
|
|
|
|
|
2021-04-02 06:05:38 +08:00
|
|
|
|
,headers: {headers_token: 'sasasas'}
|
2021-05-08 06:31:19 +08:00
|
|
|
|
,where: $.extend({}, table.config.where, {
|
|
|
|
|
test: '渲染的 test'
|
|
|
|
|
,token: '渲染的 token'
|
2021-04-02 06:05:38 +08:00
|
|
|
|
,key: 'experience'
|
|
|
|
|
,order: 'asc'
|
2021-05-08 06:31:19 +08:00
|
|
|
|
})
|
2021-04-01 03:21:16 +08:00
|
|
|
|
|
2021-04-22 10:22:45 +08:00
|
|
|
|
,done: function(){
|
|
|
|
|
//下拉菜单
|
|
|
|
|
dropdown.render({
|
|
|
|
|
elem: '#dropdown' //可绑定在任意元素中,此处以上述按钮为例
|
|
|
|
|
,data: [{
|
|
|
|
|
id: 0,
|
|
|
|
|
title: '刷新'
|
|
|
|
|
}]
|
|
|
|
|
//菜单被点击的事件
|
|
|
|
|
,click: function(obj){
|
|
|
|
|
table.reload('test');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-01 03:21:16 +08:00
|
|
|
|
,error: function(res, msg){
|
|
|
|
|
console.log(res, msg)
|
|
|
|
|
}
|
2020-11-26 22:12:46 +08:00
|
|
|
|
|
2018-08-18 20:46:14 +08:00
|
|
|
|
/*
|
|
|
|
|
,response: {
|
|
|
|
|
statusName: 'status'
|
|
|
|
|
,statusCode: 200
|
|
|
|
|
}
|
|
|
|
|
,parseData: function(res){
|
|
|
|
|
return {
|
|
|
|
|
"status": res.status
|
|
|
|
|
,"msg": res.message
|
|
|
|
|
,"count": res.total
|
|
|
|
|
,"data": res.data.list
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
});
|
|
|
|
|
|
2021-03-31 14:07:23 +08:00
|
|
|
|
//排序事件
|
|
|
|
|
table.on('sort(test)', function(obj){
|
2021-04-02 06:05:38 +08:00
|
|
|
|
console.log(obj);
|
|
|
|
|
|
2021-03-31 14:07:23 +08:00
|
|
|
|
return;
|
|
|
|
|
layer.msg('服务端排序。order by '+ obj.field + ' ' + obj.type);
|
|
|
|
|
//服务端排序
|
|
|
|
|
table.reload('test', {
|
|
|
|
|
initSort: obj
|
|
|
|
|
//,page: {curr: 1} //重新从第一页开始
|
|
|
|
|
,where: { //重新请求服务端
|
|
|
|
|
key: obj.field //排序字段
|
|
|
|
|
,order: obj.type //排序方式
|
|
|
|
|
}
|
2021-04-02 06:05:38 +08:00
|
|
|
|
}, true);
|
2021-03-31 14:07:23 +08:00
|
|
|
|
});
|
|
|
|
|
|
2018-08-18 20:46:14 +08:00
|
|
|
|
//工具栏事件
|
|
|
|
|
table.on('toolbar(test)', function(obj){
|
2021-05-08 06:31:19 +08:00
|
|
|
|
var config = obj.config;
|
|
|
|
|
var checkStatus = table.checkStatus(config.id);
|
2018-08-18 20:46:14 +08:00
|
|
|
|
switch(obj.event){
|
|
|
|
|
case 'add':
|
|
|
|
|
layer.msg('添加');
|
|
|
|
|
break;
|
|
|
|
|
case 'update':
|
|
|
|
|
layer.msg('编辑');
|
|
|
|
|
break;
|
|
|
|
|
case 'delete':
|
|
|
|
|
layer.msg('删除');
|
|
|
|
|
break;
|
|
|
|
|
case 'getCheckData':
|
|
|
|
|
var data = checkStatus.data;
|
|
|
|
|
layer.alert(JSON.stringify(data));
|
|
|
|
|
break;
|
|
|
|
|
case 'getCheckLength':
|
|
|
|
|
var data = checkStatus.data;
|
|
|
|
|
layer.msg('选中了:'+ data.length + ' 个');
|
|
|
|
|
break;
|
2021-03-31 14:07:23 +08:00
|
|
|
|
case 'getData':
|
|
|
|
|
var getData = table.getData(obj.config.id);
|
|
|
|
|
console.log(getData);
|
|
|
|
|
layer.alert(JSON.stringify(getData));
|
|
|
|
|
break;
|
2018-08-18 20:46:14 +08:00
|
|
|
|
case 'isAll':
|
|
|
|
|
layer.msg(checkStatus.isAll ? '全选': '未全选')
|
|
|
|
|
break;
|
2019-09-10 08:37:47 +08:00
|
|
|
|
case 'LAYTABLE_TIPS':
|
2021-05-08 06:31:19 +08:00
|
|
|
|
layer.alert(config.title || 'Table for layui-v'+ layui.v);
|
2019-09-10 08:37:47 +08:00
|
|
|
|
break;
|
2019-05-31 14:36:29 +08:00
|
|
|
|
case 'reload':
|
2021-04-02 06:05:38 +08:00
|
|
|
|
//深度重载
|
2021-04-05 23:41:30 +08:00
|
|
|
|
var instReload = table.reload('test', {
|
2021-04-02 06:05:38 +08:00
|
|
|
|
|
|
|
|
|
where: {
|
2021-04-01 03:21:16 +08:00
|
|
|
|
abc: 123
|
2021-05-08 06:31:19 +08:00
|
|
|
|
,test: '重载的 test'
|
2021-03-31 14:07:23 +08:00
|
|
|
|
}
|
2021-04-02 06:05:38 +08:00
|
|
|
|
,page: {curr: 5, limit: 20}
|
2021-03-31 14:07:23 +08:00
|
|
|
|
,cols: ins1.config.cols
|
2019-05-31 14:36:29 +08:00
|
|
|
|
//,height: 300
|
2019-06-03 07:57:12 +08:00
|
|
|
|
//,url: 'x'
|
2021-04-01 03:21:16 +08:00
|
|
|
|
}, true);
|
2021-03-31 14:07:23 +08:00
|
|
|
|
break;
|
|
|
|
|
case 'reload2':
|
2021-04-02 06:05:38 +08:00
|
|
|
|
//浅重载
|
2021-03-31 14:07:23 +08:00
|
|
|
|
table.reload('test', {
|
|
|
|
|
where: {
|
2021-04-01 03:21:16 +08:00
|
|
|
|
efg: 'sasasas'
|
2021-04-02 06:05:38 +08:00
|
|
|
|
//,test: '新的 test2'
|
|
|
|
|
//,token: '新的 token2'
|
2021-03-31 14:07:23 +08:00
|
|
|
|
}
|
|
|
|
|
,cols: [[
|
|
|
|
|
{type: 'checkbox', fixed: 'left'}
|
|
|
|
|
,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true, totalRowText: '合计:'}
|
2021-04-02 06:05:38 +08:00
|
|
|
|
,{field:'sex', title:'性别', width:80, edit: 'text', sort: true}
|
|
|
|
|
,{field:'experience', title:'积分', width:80, sort: true, totalRow: true, templet: '<div>{{ d.experience }} 分</div>'}
|
2021-03-31 14:07:23 +08:00
|
|
|
|
,{field:'logins', title:'登入次数', width:100, sort: true, totalRow: true}
|
|
|
|
|
,{field:'joinTime', title:'加入时间', width:120}
|
|
|
|
|
]]
|
|
|
|
|
//,height: 500
|
|
|
|
|
});
|
2019-05-31 14:36:29 +08:00
|
|
|
|
break;
|
2018-08-18 20:46:14 +08:00
|
|
|
|
};
|
2017-11-15 11:57:51 +08:00
|
|
|
|
});
|
2018-11-01 02:50:21 +08:00
|
|
|
|
|
|
|
|
|
table.on('row(test)', function(obj){
|
|
|
|
|
console.log(obj);
|
|
|
|
|
//layer.closeAll('tips');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2017-11-15 11:57:51 +08:00
|
|
|
|
|
|
|
|
|
table.render({
|
|
|
|
|
elem: '#test2'
|
|
|
|
|
,url: 'json/table/demo1.json'
|
2018-04-03 06:41:11 +08:00
|
|
|
|
,contentType: 'application/json'
|
2017-11-16 07:34:22 +08:00
|
|
|
|
,page: { //详细参数可参考 laypage 组件文档
|
|
|
|
|
curr: 5
|
|
|
|
|
,groups: 1
|
|
|
|
|
,first: false
|
|
|
|
|
,last: false
|
|
|
|
|
,layout: ['limit', 'prev', 'page', 'next', 'count'] //自定义分页布局
|
|
|
|
|
}
|
2018-08-18 20:46:14 +08:00
|
|
|
|
//,height: 300
|
2017-11-16 07:34:22 +08:00
|
|
|
|
,cellMinWidth: 80
|
2018-08-18 20:46:14 +08:00
|
|
|
|
//,skin: 'line'
|
2018-09-02 22:41:09 +08:00
|
|
|
|
,toolbar: true
|
2017-11-15 11:57:51 +08:00
|
|
|
|
,cols: [[
|
2018-09-02 22:41:09 +08:00
|
|
|
|
{field: 'id', hide: true}
|
|
|
|
|
,{field: 'username', title: '用户名'}
|
|
|
|
|
,{field: 'email', title: '邮箱'}
|
|
|
|
|
,{title:'操作', align:'center', toolbar: '#barDemo'}
|
|
|
|
|
/*
|
2017-11-15 11:57:51 +08:00
|
|
|
|
{type:'numbers'}
|
2017-11-17 14:18:42 +08:00
|
|
|
|
,{field:'id', title:'ID', unresize: true, sort: true}
|
|
|
|
|
,{field:'username', title:'用户名', templet: '#usernameTpl'}
|
2018-08-18 20:46:14 +08:00
|
|
|
|
,{field:'email', title:'邮箱'}
|
2018-08-28 15:43:16 +08:00
|
|
|
|
,{xfield:'sex', title:'性别', templet: '#switchTpl', minWidth: 85, align:'center'}
|
2017-11-16 07:34:22 +08:00
|
|
|
|
,{field:'lock', title:'是否锁定', templet: '#checkboxTpl', minWidth: 110, align:'center'}
|
|
|
|
|
,{field:'city', title:'城市'}
|
2018-09-02 22:41:09 +08:00
|
|
|
|
*/
|
2017-11-15 11:57:51 +08:00
|
|
|
|
]]
|
|
|
|
|
});
|
|
|
|
|
|
2018-05-05 16:59:53 +08:00
|
|
|
|
//监听表格行点击
|
|
|
|
|
table.on('tr', function(obj){
|
|
|
|
|
console.log(obj)
|
|
|
|
|
});
|
|
|
|
|
|
2017-11-15 11:57:51 +08:00
|
|
|
|
//监听表格复选框选择
|
|
|
|
|
table.on('checkbox(test)', function(obj){
|
|
|
|
|
console.log(obj)
|
|
|
|
|
});
|
2018-05-05 16:59:53 +08:00
|
|
|
|
|
|
|
|
|
//监听表格单选框选择
|
2018-08-18 20:46:14 +08:00
|
|
|
|
table.on('radio(test)', function(obj){
|
2018-05-05 16:59:53 +08:00
|
|
|
|
console.log(obj)
|
|
|
|
|
});
|
2017-11-15 11:57:51 +08:00
|
|
|
|
|
2018-08-18 20:46:14 +08:00
|
|
|
|
//监听表格单选框选择
|
|
|
|
|
table.on('rowDouble(test)', function(obj){
|
|
|
|
|
console.log(obj);
|
|
|
|
|
});
|
|
|
|
|
|
2017-11-15 11:57:51 +08:00
|
|
|
|
//监听单元格编辑
|
2018-08-18 20:46:14 +08:00
|
|
|
|
table.on('edit(test)', function(obj){
|
2017-11-15 11:57:51 +08:00
|
|
|
|
var value = obj.value //得到修改后的值
|
|
|
|
|
,data = obj.data //得到所在行所有键值
|
|
|
|
|
,field = obj.field; //得到字段
|
|
|
|
|
|
2018-08-18 20:46:14 +08:00
|
|
|
|
console.log(obj)
|
2017-11-15 11:57:51 +08:00
|
|
|
|
});
|
|
|
|
|
|
2018-08-18 20:46:14 +08:00
|
|
|
|
//监听行工具事件
|
2017-11-15 11:57:51 +08:00
|
|
|
|
table.on('tool(test)', function(obj){
|
|
|
|
|
var data = obj.data;
|
2018-08-18 20:46:14 +08:00
|
|
|
|
//console.log(obj)
|
2017-11-15 11:57:51 +08:00
|
|
|
|
if(obj.event === 'del'){
|
|
|
|
|
layer.confirm('真的删除行么', function(index){
|
|
|
|
|
obj.del();
|
|
|
|
|
layer.close(index);
|
|
|
|
|
});
|
|
|
|
|
} else if(obj.event === 'edit'){
|
|
|
|
|
layer.prompt({
|
|
|
|
|
formType: 2
|
2018-08-18 20:46:14 +08:00
|
|
|
|
,value: data.email
|
2017-11-15 11:57:51 +08:00
|
|
|
|
}, function(value, index){
|
|
|
|
|
obj.update({
|
2018-08-18 20:46:14 +08:00
|
|
|
|
email: value
|
2017-11-15 11:57:51 +08:00
|
|
|
|
});
|
|
|
|
|
layer.close(index);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-08-18 20:46:14 +08:00
|
|
|
|
//return;
|
|
|
|
|
|
2017-11-15 11:57:51 +08:00
|
|
|
|
//直接赋值数据
|
|
|
|
|
table.render({
|
2017-08-21 08:51:13 +08:00
|
|
|
|
elem: '#demo'
|
2017-11-19 07:47:16 +08:00
|
|
|
|
//,width: 900
|
|
|
|
|
//,height: 274
|
|
|
|
|
,cols: [[ //标题栏
|
|
|
|
|
{type: 'checkbox', LAY_CHECKED: true}
|
|
|
|
|
,{field: 'id', title: 'ID', width: 80, sort: true}
|
|
|
|
|
,{type: 'space', width: 100} //空列
|
|
|
|
|
,{field: 'username', title: '用户名', width: 120}
|
|
|
|
|
,{field: 'email', title: '邮箱', width: 150}
|
|
|
|
|
,{field: 'sign', title: '签名', width: 150}
|
|
|
|
|
,{field: 'sex', title: '性别', width: 80}
|
|
|
|
|
,{field: 'city', title: '城市', width: 100}
|
|
|
|
|
,{field: 'experience', title: '积分', width: 80, sort: true}
|
|
|
|
|
]]
|
2017-08-21 08:51:13 +08:00
|
|
|
|
,data: [{
|
|
|
|
|
"id": "10001"
|
|
|
|
|
,"username": "杜甫"
|
|
|
|
|
,"email": "xianxin@layui.com"
|
|
|
|
|
,"sex": "男"
|
|
|
|
|
,"city": "浙江杭州"
|
|
|
|
|
,"sign": "人生恰似一场修行"
|
|
|
|
|
,"experience": "116"
|
|
|
|
|
,"ip": "192.168.0.8"
|
|
|
|
|
,"logins": "108"
|
|
|
|
|
,"joinTime": "2016-10-14"
|
|
|
|
|
}, {
|
|
|
|
|
"id": "10002"
|
|
|
|
|
,"username": "李白"
|
|
|
|
|
,"email": "xianxin@layui.com"
|
|
|
|
|
,"sex": "男"
|
|
|
|
|
,"city": "浙江杭州"
|
|
|
|
|
,"sign": "人生恰似一场修行"
|
|
|
|
|
,"experience": "12"
|
|
|
|
|
,"ip": "192.168.0.8"
|
|
|
|
|
,"logins": "106"
|
|
|
|
|
,"joinTime": "2016-10-14"
|
|
|
|
|
,"LAY_CHECKED": true
|
|
|
|
|
}, {
|
|
|
|
|
"id": "10003"
|
|
|
|
|
,"username": "王勃"
|
|
|
|
|
,"email": "xianxin@layui.com"
|
|
|
|
|
,"sex": "男"
|
|
|
|
|
,"city": "浙江杭州"
|
|
|
|
|
,"sign": "人生恰似一场修行"
|
|
|
|
|
,"experience": "65"
|
|
|
|
|
,"ip": "192.168.0.8"
|
|
|
|
|
,"logins": "106"
|
|
|
|
|
,"joinTime": "2016-10-14"
|
|
|
|
|
}, {
|
|
|
|
|
"id": "10004"
|
|
|
|
|
,"username": "贤心"
|
|
|
|
|
,"email": "xianxin@layui.com"
|
|
|
|
|
,"sex": "男"
|
|
|
|
|
,"city": "浙江杭州"
|
|
|
|
|
,"sign": "人生恰似一场修行"
|
|
|
|
|
,"experience": "666"
|
|
|
|
|
,"ip": "192.168.0.8"
|
|
|
|
|
,"logins": "106"
|
|
|
|
|
,"joinTime": "2016-10-14"
|
|
|
|
|
}, {
|
|
|
|
|
"id": "10005"
|
|
|
|
|
,"username": "贤心"
|
|
|
|
|
,"email": "xianxin@layui.com"
|
|
|
|
|
,"sex": "男"
|
|
|
|
|
,"city": "浙江杭州"
|
|
|
|
|
,"sign": "人生恰似一场修行"
|
|
|
|
|
,"experience": "86"
|
|
|
|
|
,"ip": "192.168.0.8"
|
|
|
|
|
,"logins": "106"
|
|
|
|
|
,"joinTime": "2016-10-14"
|
|
|
|
|
}, {
|
|
|
|
|
"id": "10006"
|
|
|
|
|
,"username": "贤心"
|
|
|
|
|
,"email": "xianxin@layui.com"
|
|
|
|
|
,"sex": "男"
|
|
|
|
|
,"city": "浙江杭州"
|
|
|
|
|
,"sign": "人生恰似一场修行"
|
|
|
|
|
,"experience": "12"
|
|
|
|
|
,"ip": "192.168.0.8"
|
|
|
|
|
,"logins": "106"
|
|
|
|
|
,"joinTime": "2016-10-14"
|
|
|
|
|
}, {
|
|
|
|
|
"id": "10007"
|
|
|
|
|
,"username": "贤心"
|
|
|
|
|
,"email": "xianxin@layui.com"
|
|
|
|
|
,"sex": "男"
|
|
|
|
|
,"city": "浙江杭州"
|
|
|
|
|
,"sign": "人生恰似一场修行"
|
|
|
|
|
,"experience": "16"
|
|
|
|
|
,"ip": "192.168.0.8"
|
|
|
|
|
,"logins": "106"
|
|
|
|
|
,"joinTime": "2016-10-14"
|
|
|
|
|
}, {
|
|
|
|
|
"id": "10008"
|
|
|
|
|
,"username": "贤心"
|
|
|
|
|
,"email": "xianxin@layui.com"
|
|
|
|
|
,"sex": "男"
|
|
|
|
|
,"city": "浙江杭州"
|
|
|
|
|
,"sign": "人生恰似一场修行"
|
|
|
|
|
,"experience": "106"
|
|
|
|
|
,"ip": "192.168.0.8"
|
|
|
|
|
,"logins": "106"
|
|
|
|
|
,"joinTime": "2016-10-14"
|
|
|
|
|
}]
|
2017-11-19 07:47:16 +08:00
|
|
|
|
|
2017-08-21 08:51:13 +08:00
|
|
|
|
,skin: 'row' //表格风格
|
|
|
|
|
,even: true
|
|
|
|
|
//,size: 'lg' //尺寸
|
|
|
|
|
|
|
|
|
|
,page: true //是否显示分页
|
|
|
|
|
,limits: [3,5,10]
|
|
|
|
|
,limit: 3 //每页默认显示的数量
|
|
|
|
|
//,loading: false //请求数据时,是否显示loading
|
2017-08-30 17:10:33 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-08-21 08:51:13 +08:00
|
|
|
|
|
|
|
|
|
var $ = layui.jquery, active = {
|
2018-08-18 20:46:14 +08:00
|
|
|
|
parseTable: function(){
|
2017-11-19 07:47:16 +08:00
|
|
|
|
table.init('parse-table-demo', {
|
|
|
|
|
limit: 3
|
|
|
|
|
});
|
2017-08-21 08:51:13 +08:00
|
|
|
|
}
|
2018-05-05 16:59:53 +08:00
|
|
|
|
,add: function(){
|
|
|
|
|
table.addRow('test')
|
|
|
|
|
}
|
2017-08-21 08:51:13 +08:00
|
|
|
|
};
|
2018-05-05 16:59:53 +08:00
|
|
|
|
$('i').on('click', function(){
|
|
|
|
|
var type = $(this).data('type');
|
|
|
|
|
active[type] ? active[type].call(this) : '';
|
|
|
|
|
});
|
2017-08-21 08:51:13 +08:00
|
|
|
|
$('.layui-btn').on('click', function(){
|
|
|
|
|
var type = $(this).data('type');
|
|
|
|
|
active[type] ? active[type].call(this) : '';
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|