12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <title>加入表单元素 - 数据表格</title>
- <div class="layui-card layadmin-header">
- <div class="layui-breadcrumb" lay-filter="breadcrumb">
- <a lay-href="">主页</a>
- <a><cite>组件</cite></a>
- <a><cite>数据表格</cite></a>
- <a><cite>加入表单元素</cite></a>
- </div>
- </div>
-
- <div class="layui-fluid">
- <div class="layui-row layui-col-space15">
- <div class="layui-col-md12">
- <div class="layui-card">
- <div class="layui-card-header">加入表单元素</div>
- <div class="layui-card-body">
- <table class="layui-hide" id="test-table-form"></table>
-
- <script type="text/html" id="test-table-switchTpl">
- <!-- 这里的 checked 的状态只是演示 -->
- <input type="checkbox" name="sex" lay-skin="switch" lay-text="女|男" lay-filter="test-table-sexDemo"
- value="{{ d.id }}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.id == 10003 ? 'checked' : '' }}>
- </script>
-
- <script type="text/html" id="test-table-checkboxTpl">
- <!-- 这里的 checked 的状态只是演示 -->
- <input type="checkbox" name="lock" title="锁定" lay-filter="test-table-lockDemo"
- value="{{d.id}}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.id == 10006 ? 'checked' : '' }}>
- </script>
-
- </div>
- </div>
- </div>
- </div>
- </div>
-
- <script>
- layui.use(['admin', 'table', 'form'], function(){
- var table = layui.table
- ,form = layui.form
- ,$ = layui.$;
-
- table.render({
- elem: '#test-table-form'
- ,url:'/demo/table/user/'
- ,cellMinWidth: 80
- ,cols: [[
- {type:'numbers'}
- ,{type: 'checkbox'}
- ,{field:'id', title:'ID', width:100, unresize: true, sort: true}
- ,{field:'username', title:'用户名'}
- ,{field:'city', title:'城市'}
- ,{field:'wealth', title: '财富', minWidth:120, sort: true}
- ,{field:'sex', title:'性别', width:85, templet: '#test-table-switchTpl', unresize: true}
- ,{field:'lock', title:'是否锁定', width:110, templet: '#test-table-checkboxTpl', unresize: true}
- ]]
- ,page: true
- });
-
- //监听性别操作
- form.on('switch(test-table-sexDemo)', function(obj){
- var json = JSON.parse(decodeURIComponent($(this).data('json')));
- layer.tips(this.value + ' ' + this.name + ':'+ obj.elem.checked, obj.othis);
-
- json = table.clearCacheKey(json);
- console.log(json); //当前行数据
- });
-
- //监听锁定操作
- form.on('checkbox(test-table-lockDemo)', function(obj){
- var json = JSON.parse(decodeURIComponent($(this).data('json')));
- layer.tips(this.value + ' ' + this.name + ':'+ obj.elem.checked, obj.othis);
-
- json = table.clearCacheKey(json);
- console.log(json); //当前行数据
- });
-
- });
- </script>
|