layui/examples/table.html

340 lines
9.8 KiB
HTML
Raw Normal View History

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>
<link rel="stylesheet" href="../src/css/layui.css">
<style>
2022-08-25 16:51:51 +08:00
body{padding: 32px; /*overflow-y: scroll;*/}
2023-05-04 10:04:08 +08:00
.layui-table-view{margin: 8px 0;}
2021-04-22 10:22:45 +08:00
</style>
2017-08-21 08:51:13 +08:00
</head>
<body>
2022-05-18 22:35:13 +08:00
<div class="layui-btn-container">
2022-06-22 01:07:12 +08:00
<a href="table.html" class="layui-btn layui-btn-primary layui-border-green">表格综合</a>
<a href="table-test.html" class="layui-btn">表格操作</a>
2022-05-18 22:35:13 +08:00
<a href="table-static.html" class="layui-btn">静态表格</a>
</div>
2021-05-31 08:57:00 +08:00
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
2022-08-25 16:51:51 +08:00
<table id="test"></table>
<table id="test-data"></table>
<table id="test-arr"></table>
<table id="test-json"></table>
2017-11-17 14:18:42 +08:00
2018-08-18 20:46:14 +08:00
<div style="display: none1;">
2023-02-13 13:05:47 +08:00
<table class="layui-table" lay-data="{width:800, height: 300, url:'json/table/demo2.json', page: true, even: true, limit: 6, toolbar: true}">
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>
2022-08-24 11:27:31 +08:00
<th lay-data="{align:'center'}" colspan="5">地址</th>
2018-08-18 20:46:14 +08:00
<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>
2022-08-24 11:27:31 +08:00
<th lay-data="{field:'address', width:120}">小区</th>
<th lay-data="{field:'house', width:150}">单元</th>
2018-08-18 20:46:14 +08:00
</tr>
</thead>
</table>
2017-08-21 08:51:13 +08:00
2022-07-06 09:31:38 +08:00
<table class="layui-table" lay-data="{url:'json/table/demo2.json', page: true, limit: 6, toolbar: true}">
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
<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>
2018-08-18 20:46:14 +08:00
</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
2022-08-24 11:27:31 +08:00
<script src="../src/layui.js" src1="https://cdn.staticfile.org/layui/2.7.6/layui.js"></script>
2017-08-21 08:51:13 +08:00
<script>
2022-06-22 01:07:12 +08:00
layui.use('table', function(){
var $ = layui.$;
var table = layui.table;
2022-08-25 16:51:51 +08:00
// 常规示例
2017-11-15 11:57:51 +08:00
table.render({
2022-08-25 16:51:51 +08:00
elem: '#test'
2017-11-15 11:57:51 +08:00
,url: 'json/table/demo1.json'
2022-08-25 16:51:51 +08:00
//,contentType: 'application/json' // 参数为 json 格式传递
2023-05-04 10:04:08 +08:00
,page: !1 ? false : { // 详细参数可参考 laypage 组件文档
2017-11-16 07:34:22 +08:00
curr: 5
,groups: 1
,first: false
,last: false
,layout: ['limit', 'prev', 'page', 'next', 'count'] //自定义分页布局
}
2023-05-04 10:04:08 +08:00
,height: 300
2017-11-16 07:34:22 +08:00
,cellMinWidth: 80
2018-08-18 20:46:14 +08:00
//,skin: 'line'
2022-06-27 00:29:24 +08:00
//,size: 'lg'
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
]]
});
2018-08-18 20:46:14 +08:00
//return;
2022-06-22 01:07:12 +08:00
// 直接赋值数据
2017-11-15 11:57:51 +08:00
table.render({
2022-08-25 16:51:51 +08:00
elem: '#test-data'
2017-11-19 07:47:16 +08:00
//,width: 900
//,height: 274
2022-08-24 11:27:31 +08:00
,toolbar: true
2017-11-19 07:47:16 +08:00
,cols: [[ //标题栏
//{type: 'space'},
{type: 'checkbox', LAY_CHECKED: true},
{field: 'id', title: 'ID', width: 80, sort: true},
{field: 'username', title: '用户名', width: 120},
{field: 'email', title: '邮箱', width: 150},
{field: 'sign', title: '签名', minWidth: 150},
{field: 'sex', title: '性别', width: 80},
{field: 'city', title: '城市', width: 100},
{field: 'experience', title: '积分', width: 80, sort: true, totalRow: '{{= parseInt(d.TOTAL_NUMS) }}'}
2022-08-24 11:27:31 +08:00
,{field:'ip', title:'IP', width: 120, align: 'right'}
,{field:'joinTime', title:'加入时间', width: 120}
2017-11-19 07:47:16 +08:00
]]
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' //尺寸
2017-08-21 08:51:13 +08:00
,page: true //是否显示分页
,limits: [3,5,10]
,limit: 3 //每页默认显示的数量
,totalRow: true
2017-08-21 08:51:13 +08:00
//,loading: false //请求数据时是否显示loading
2017-08-30 17:10:33 +08:00
});
2022-08-25 16:51:51 +08:00
// 渲染数组成员非对象的内容v2.8.0 新增)
table.render({
elem: '#test-arr',
data: ['a','b','c','d','e','f','g','h','i'],
page: true,
limit: 3,
cols: [[
{type: 'numbers', title: '序号'},
{field: 'LAY_KEY', title: '内容'}
]]
});
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>