form.html 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <title>加入表单元素 - 数据表格</title>
  2. <div class="layui-card layadmin-header">
  3. <div class="layui-breadcrumb" lay-filter="breadcrumb">
  4. <a lay-href="">主页</a>
  5. <a><cite>组件</cite></a>
  6. <a><cite>数据表格</cite></a>
  7. <a><cite>加入表单元素</cite></a>
  8. </div>
  9. </div>
  10. <div class="layui-fluid">
  11. <div class="layui-row layui-col-space15">
  12. <div class="layui-col-md12">
  13. <div class="layui-card">
  14. <div class="layui-card-header">加入表单元素</div>
  15. <div class="layui-card-body">
  16. <table class="layui-hide" id="test-table-form"></table>
  17. <script type="text/html" id="test-table-switchTpl">
  18. <!-- 这里的 checked 的状态只是演示 -->
  19. <input type="checkbox" name="sex" lay-skin="switch" lay-text="女|男" lay-filter="test-table-sexDemo"
  20. value="{{ d.id }}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.id == 10003 ? 'checked' : '' }}>
  21. </script>
  22. <script type="text/html" id="test-table-checkboxTpl">
  23. <!-- 这里的 checked 的状态只是演示 -->
  24. <input type="checkbox" name="lock" title="锁定" lay-filter="test-table-lockDemo"
  25. value="{{d.id}}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.id == 10006 ? 'checked' : '' }}>
  26. </script>
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. <script>
  33. layui.use(['admin', 'table', 'form'], function(){
  34. var table = layui.table
  35. ,form = layui.form
  36. ,$ = layui.$;
  37. table.render({
  38. elem: '#test-table-form'
  39. ,url:'/demo/table/user/'
  40. ,cellMinWidth: 80
  41. ,cols: [[
  42. {type:'numbers'}
  43. ,{type: 'checkbox'}
  44. ,{field:'id', title:'ID', width:100, unresize: true, sort: true}
  45. ,{field:'username', title:'用户名'}
  46. ,{field:'city', title:'城市'}
  47. ,{field:'wealth', title: '财富', minWidth:120, sort: true}
  48. ,{field:'sex', title:'性别', width:85, templet: '#test-table-switchTpl', unresize: true}
  49. ,{field:'lock', title:'是否锁定', width:110, templet: '#test-table-checkboxTpl', unresize: true}
  50. ]]
  51. ,page: true
  52. });
  53. //监听性别操作
  54. form.on('switch(test-table-sexDemo)', function(obj){
  55. var json = JSON.parse(decodeURIComponent($(this).data('json')));
  56. layer.tips(this.value + ' ' + this.name + ':'+ obj.elem.checked, obj.othis);
  57. json = table.clearCacheKey(json);
  58. console.log(json); //当前行数据
  59. });
  60. //监听锁定操作
  61. form.on('checkbox(test-table-lockDemo)', function(obj){
  62. var json = JSON.parse(decodeURIComponent($(this).data('json')));
  63. layer.tips(this.value + ' ' + this.name + ':'+ obj.elem.checked, obj.othis);
  64. json = table.clearCacheKey(json);
  65. console.log(json); //当前行数据
  66. });
  67. });
  68. </script>