radio.html 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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-radio" lay-filter="test-table-radio"></table>
  17. <script type="text/html" id="test-table-radio-toolbarDemo">
  18. <div class="layui-btn-container">
  19. <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
  20. </div>
  21. </script>
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. </div>
  27. <script>
  28. layui.use(['admin', 'table'], function(){
  29. var admin = layui.admin
  30. ,table = layui.table;
  31. table.render({
  32. elem: '#test-table-radio'
  33. ,url: './json/table/user.js'
  34. ,toolbar: '#test-table-radio-toolbarDemo'
  35. ,cols: [[
  36. {type:'radio'}
  37. ,{field:'id', width:80, title: 'ID', sort: true}
  38. ,{field:'username', width:80, title: '用户名'}
  39. ,{field:'sex', width:80, title: '性别', sort: true}
  40. ,{field:'city', width:80, title: '城市'}
  41. ,{field:'sign', title: '签名', minWidth: 100}
  42. ,{field:'experience', width:80, title: '积分', sort: true}
  43. ,{field:'score', width:80, title: '评分', sort: true}
  44. ,{field:'classify', width:80, title: '职业'}
  45. ,{field:'wealth', width:135, title: '财富', sort: true}
  46. ]]
  47. ,page: true
  48. });
  49. //头工具栏事件
  50. table.on('toolbar(test-table-radio)', function(obj){
  51. var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
  52. switch(obj.event){
  53. case 'getCheckData':
  54. var data = checkStatus.data; //获取选中行数据
  55. layer.alert(JSON.stringify(data));
  56. break;
  57. };
  58. });
  59. });
  60. </script>