This commit is contained in:
sentsin
2017-11-15 11:57:51 +08:00
parent d12b73f3e3
commit 3a6735e32b
45 changed files with 660 additions and 516 deletions

View File

@@ -15,66 +15,38 @@ body{padding: 20px;}
</head>
<body>
<table id="test2" lay-filter="test2"></table>
<div class="layui-btn-group">
<button class="layui-btn" data-type="getCheckData">获取选中行数据</button>
<button class="layui-btn" data-type="getCheckLength">获取选中数目</button>
<button class="layui-btn" data-type="isAll">验证是否全选</button>
</div>
<table class="layui-table" lay-data="{width:900, height:'full-100', url:'json/table/demo1.json', page:true, id:'test'}" lay-filter="test">
<thead>
<tr>
<th lay-data="{checkbox:true, fixed: true}"></th>
<th lay-data="{field:'id', width:80, fixed: true, sort: true}">ID</th>
<th lay-data="{field:'username', width:120, sort: true, edit: 'text', templet: '#usernameTpl'}">用户名</th>
<th lay-data="{field:'email', width:150}">邮箱</th>
<th lay-data="{field:'sex', width:80}">性别</th>
<th lay-data="{field:'city', width:100}">城市</th>
<th lay-data="{field:'sign', width:150}">签名</th>
<th lay-data="{field:'experience', width:80, sort: true, edit: 'text'}">积分</th>
<th lay-data="{field:'ip', width:120}">IP</th>
<th lay-data="{field:'logins', width:100}">登入次数</th>
<th lay-data="{field:'joinTime', width:120}">加入时间</th>
<th lay-data="{fixed: 'right', toolbar: '#barDemo', width:150, align:'center'}">操作</th>
</tr>
</thead>
</table>
<table id="test" lay-filter="test"></table>
<div class="layui-hide" id="barDemo">
<a class="layui-btn layui-btn-mini" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">删除</a>
</div>
<table id="demo"></table>
<table class="layui-table" lay-data="{height:350, url:'json/table/demo1.json', page: true}">
<thead>
<tr>
<th lay-data="{field:'id', width:80, fixed:true, unresize: true, sort: true}">ID</th>
<th lay-data="{checkbox:true}"></th>
<th lay-data="{field:'username', width:120, templet: '#usernameTpl'}">用户名</th>
<th lay-data="{field:'email', width:150}">邮箱</th>
<th lay-data="{field:'sex', width:80, sort: true}">性别</th>
<th lay-data="{field:'city', width:100}">城市</th>
<th lay-data="{field:'sign', width:150}">签名</th>
<th lay-data="{field:'experience', width:80, sort: true}">积分</th>
<th lay-data="{field:'ip', width:120}">IP</th>
<th lay-data="{field:'logins', width:100, sort: true}">登入次数</th>
<th lay-data="{field:'joinTime', width:120}">加入时间</th>
<th lay-data="{fixed: 'right', toolbar: '#barDemo', width:150}">操作</th>
</tr>
</thead>
</table>
<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>
<script type="text/html" id="usernameTpl">
<a href="" class="layui-table-link">{{d.username || ''}}</a>
</script>
<script type="text/html" id="switchTpl">
<input type="checkbox" name="yyy" lay-skin="switch" lay-text="女|男">
</script>
<script type="text/html" id="checkboxTpl">
<input type="checkbox" name="" title="锁定" checked>
</script>
<script type="text/html" id="LAY_table_tpl_email">
<span {{# if(!d.activate){ }}style="color:#999"{{# } }}>{{ d.email }}</span>
</script>
<table class="layui-table" lay-data="{width:800, height:235, url:'json/table/demo2.json', page: true, limit: 6}">
<table class="layui-table" lay-data="{width:800, height: 300, url:'json/table/demo2.json', page: true, limit: 6}">
<thead>
<tr>
<th lay-data="{checkbox:true, fixed:'left'}" rowspan="2"></th>
@@ -91,10 +63,10 @@ body{padding: 20px;}
</thead>
</table>
<table class="layui-table" lay-data="{height:315, url:'json/table/demo2.json', page: true, limit: 6}">
<table class="layui-table" lay-data="{url:'json/table/demo2.json', page: true, limit: 6}">
<thead>
<tr>
<th lay-data="{field:'username', width:80}" rowspan="3">联系人</th>
<th lay-data="{field:'username'}" rowspan="3">联系人</th>
<th lay-data="{field:'amount', width:120}" rowspan="3">金额</th>
<th lay-data="{align:'center'}" colspan="5">地址1</th>
<th lay-data="{align:'center'}" colspan="2">地址2</th>
@@ -110,11 +82,13 @@ body{padding: 20px;}
</tr>
<tr>
<th lay-data="{field:'address', width:120}">小区</th>
<th lay-data="{field:'house', width:120}">单元</th>
<th lay-data="{field:'house', width:150}">单元</th>
</tr>
</thead>
</table>
<table id="demo"></table>
<div class="layui-btn-group">
<button class="layui-btn" data-type="parseTable">转化为数据表格</button>
@@ -190,15 +164,116 @@ body{padding: 20px;}
</tbody>
</table>
<script type="text/html" id="toolbarDemo">
<i class="layui-icon">&#xe654;</i>
<i class="layui-icon">&#xe640;</i>
</script>
<script src="../src/layui.js" charset="utf-8"></script>
<script>
layui.use('table', function(){
var table = layui.table;
//方法级渲染
window.demoTable = table.render({
//渲染
table.render({
elem: '#test'
,height: 350
,url: 'json/table/demo1.json'
,page: {}
,toolbar: '#toolbarDemo'
,cols: [[
{checkbox:true, fixed: 'left'}
,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
,{field:'username', title:'用户名', width:120, edit: 'text', templet: '#usernameTpl'}
,{field:'email', title:'邮箱', width:150}
,{field:'sex', title:'性别', width:80, edit: 'text', sort: true}
,{field:'city', title:'城市', width:100}
,{field:'sign', title:'签名'}
,{field:'experience', title:'积分', width:80, sort: true}
,{field:'ip', title:'IP', width:120}
,{field:'logins', title:'登入次数', width:100, sort: true}
,{field:'joinTime', title:'加入时间', width:120}
,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
,
]]
});
table.render({
elem: '#test2'
,url: 'json/table/demo1.json'
,page: {}
//,height: 300
,cols: [[
{type:'numbers'}
,{type: 'checkbox'}
,{field:'id', title:'ID', width:100, unresize: true, sort: true}
,{field:'username', title:'用户名', templet: '#usernameTpl'}
,{field:'email', title:'邮箱'}
,{field:'sex', title:'性别', width:85, templet: '#switchTpl'}
,{field:'lock', title:'是否锁定', width:110, templet: '#checkboxTpl'}
,{field:'city', title:'城市', width: 100}
//,{field:'sign', title:'签名', width:150}
//,{field:'experience', title:'积分', width:80, sort: true}
//,{field:'ip', title:'IP', width:120}
//,{field:'logins', title:'登入次数', width:100, sort: true}
//,{field:'joinTime', title:'加入时间', width:120}
//,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
,
]]
});
//监听表格复选框选择
table.on('checkbox(test)', function(obj){
console.log(obj)
});
//监听单元格编辑
table.on('edit(test)', function(obj){
var value = obj.value //得到修改后的值
,data = obj.data //得到所在行所有键值
,field = obj.field; //得到字段
});
//监听工具条
table.on('tool(test)', function(obj){
var data = obj.data;
if(obj.event === 'del'){
layer.confirm('真的删除行么', function(index){
obj.del();
layer.close(index);
});
} else if(obj.event === 'edit'){
layer.prompt({
formType: 2
,value: data.username
}, function(value, index){
obj.update({
username: value
});
layer.close(index);
});
}
});
//监听排序
table.on('sort(test)', function(obj){
console.log(this, obj.field, obj.type)
return;
table.reload('test', {
initSort: obj
,where: { //重新请求服务端
key: obj.field //排序字段
,order: obj.type //排序方式
}
//,height: 300
});
});
//直接赋值数据
table.render({
elem: '#demo'
//,url: 'json/table/demo1.json'
,data: [{
"id": "10001"
,"username": "杜甫"
@@ -312,57 +387,6 @@ layui.use('table', function(){
,limits: [3,5,10]
,limit: 3 //每页默认显示的数量
//,loading: false //请求数据时是否显示loading
//,id: 'test' //ID
});
//监听表格复选框选择
table.on('checkbox(test)', function(obj){
console.log(obj)
});
//监听单元格编辑
table.on('edit(test)', function(obj){
var value = obj.value //得到修改后的值
,data = obj.data //得到所在行所有键值
,field = obj.field; //得到字段
});
//监听工具条
table.on('tool(test)', function(obj){
var data = obj.data;
if(obj.event === 'del'){
layer.confirm('真的删除行么', function(index){
obj.del();
layer.close(index);
});
} else if(obj.event === 'edit'){
layer.prompt({
formType: 2
,value: data.username
}, function(value, index){
obj.update({
username: value
});
layer.close(index);
});
}
});
//监听排序
table.on('sort(test)', function(obj){
console.log(this, obj.field, obj.type)
return;
table.reload('test', {
initSort: obj
,where: { //重新请求服务端
key: obj.field //排序字段
,order: obj.type //排序方式
}
//,height: 300
});
});