toolbar.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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-toolbar" lay-filter="test-table-toolbar"></table>
  17. <script type="text/html" id="test-table-toolbar-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. <script type="text/html" id="test-table-toolbar-barDemo">
  25. <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  26. <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
  27. </script>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. <script>
  34. layui.use(['admin', 'table'], function(){
  35. var admin = layui.admin
  36. ,table = layui.table;
  37. table.render({
  38. elem: '#test-table-toolbar'
  39. // ,url:'./json/table/demo.js'
  40. ,url:'/test/select'
  41. ,method:'post'
  42. ,toolbar: '#test-table-toolbar-toolbarDemo'
  43. ,title: '用户数据表'
  44. ,cols: [[
  45. {type: 'checkbox', fixed: 'left'}
  46. ,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
  47. ,{field:'license', title:'车牌', width:120, edit: 'text'}
  48. ,{field:'licenseColor', title:'车牌颜色', width:120, edit: 'text'}
  49. ,{field:'ownerName', title:'用户名', width:120, edit: 'text'}
  50. ,{field:'purpose', title:'使用性质', width:120, edit: 'text'}
  51. ,{field:'emission', title:'排放阶段', width:120, edit: 'text'}
  52. ,{field:'detectionClassification', title:'检测分类', width:120, edit: 'text'}
  53. ,{field:'brand', title:'厂牌型号', width:120, edit: 'text'}
  54. ,{field:'vehicleModel', title:'车辆型号', width:120, edit: 'text'}
  55. ,{field:'intake', title:'进气方式', width:120, edit: 'text'}
  56. ,{field:'vehicleType', title:'车辆类型', width:120, edit: 'text'}
  57. ,{field:'totalMax', title:'最大总质量KG', width:120, edit: 'text'}
  58. ,{field:'total', title:'基准质量', width:120, edit: 'text'}
  59. ,{field:'gearbox', title:'变速箱类型', width:120, edit: 'text'}
  60. ,{field:'fuel', title:'燃料类型', width:120, edit: 'text'}
  61. ,{field:'driverType', title:'驱动类型', width:120, edit: 'text'}
  62. ,{field:'registerDate', title:'登记日期', width:120, edit: 'text'}
  63. ,{field:'vin', title:'车架号', width:120, edit: 'text'}
  64. ,{field:'operationalType', title:'运营类型', width:120, edit: 'text'}
  65. ,{field:'address', title:'地址', width:120, edit: 'text'}
  66. ,{field:'engineModel', title:'发动机型号', width:120, edit: 'text'}
  67. ,{field:'detectDriver', title:'检测驾驶员', width:120, edit: 'text'}
  68. ,{field:'engineNum', title:'发动机号', width:120, edit: 'text'}
  69. ,{field:'odometerReading', title:'里程表读数', width:120, edit: 'text'}
  70. // ,{field:'email', title:'邮箱', width:150, edit: 'text', templet: function(res){
  71. // return '<em>'+ res.email +'</em>'
  72. // }}
  73. // ,{field:'sex', title:'性别', width:80, edit: 'text', sort: true}
  74. // ,{field:'city', title:'城市', width:100}
  75. // ,{field:'sign', title:'签名'}
  76. // ,{field:'experience', title:'积分', width:80, sort: true}
  77. // ,{field:'ip', title:'IP', width:120}
  78. // ,{field:'logins', title:'登入次数', width:100, sort: true}
  79. // ,{field:'joinTime', title:'加入时间', width:120}
  80. ,{fixed: 'right', title:'操作', toolbar: '#test-table-toolbar-barDemo', width:150}
  81. ]]
  82. ,page: true
  83. });
  84. //头工具栏事件
  85. table.on('toolbar(test-table-toolbar)', function(obj){
  86. var checkStatus = table.checkStatus(obj.config.id);
  87. switch(obj.event){
  88. case 'getCheckData':
  89. var data = checkStatus.data;
  90. layer.alert(JSON.stringify(data));
  91. break;
  92. case 'getCheckLength':
  93. var data = checkStatus.data;
  94. layer.msg('选中了:'+ data.length + ' 个');
  95. break;
  96. case 'isAll':
  97. layer.msg(checkStatus.isAll ? '全选': '未全选');
  98. break;
  99. };
  100. });
  101. //监听行工具事件
  102. table.on('tool(test-table-toolbar)', function(obj){
  103. var data = obj.data;
  104. if(obj.event === 'del'){
  105. layer.confirm('真的删除行么', function(index){
  106. obj.del();
  107. layer.close(index);
  108. });
  109. } else if(obj.event === 'edit'){
  110. layer.prompt({
  111. formType: 2
  112. ,value: data.email
  113. }, function(value, index){
  114. obj.update({
  115. email: value
  116. });
  117. layer.close(index);
  118. });
  119. }
  120. });
  121. });
  122. </script>