totalRow.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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-totalRow" lay-filter="test-table-totalRow"></table>
  17. <script type="text/html" id="test-table-totalRow-toolbarDemo">
  18. <div class="layui-btn-container">
  19. <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
  20. <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
  21. <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
  22. </div>
  23. </script>
  24. </div>
  25. </div>
  26. </div>
  27. </div>
  28. </div>
  29. <script>
  30. layui.use(['admin', 'table'], function(){
  31. var admin = layui.admin
  32. ,table = layui.table;
  33. table.render({
  34. elem: '#test-table-totalRow'
  35. ,url:'./json/table/demo.js'
  36. ,toolbar: '#test-table-totalRow-toolbarDemo'
  37. ,title: '用户数据表'
  38. ,totalRow: true
  39. ,cols: [[
  40. {type: 'checkbox', fixed: 'left'}
  41. ,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true, totalRowText: '合计'}
  42. ,{field:'username', title:'用户名', width:120, edit: 'text'}
  43. ,{field:'experience', title:'积分', width:80, sort: true, totalRow: true}
  44. ,{field:'sex', title:'性别', width:80, edit: 'text', sort: true}
  45. ,{field:'logins', title:'登入次数', width:100, sort: true, totalRow: true}
  46. ,{field:'sign', title:'签名'}
  47. ]]
  48. ,page: true
  49. });
  50. //头工具栏事件
  51. table.on('toolbar(test-table-totalRow)', function(obj){
  52. var checkStatus = table.checkStatus(obj.config.id);
  53. switch(obj.event){
  54. case 'getCheckData':
  55. var data = checkStatus.data;
  56. layer.alert(JSON.stringify(data));
  57. break;
  58. case 'getCheckLength':
  59. var data = checkStatus.data;
  60. layer.msg('选中了:'+ data.length + ' 个');
  61. break;
  62. case 'isAll':
  63. layer.msg(checkStatus.isAll ? '全选': '未全选');
  64. break;
  65. };
  66. });
  67. });
  68. </script>