crud.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <!DOCTYPE HTML>
  2. <html lang="zh-cn">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <title>通用增删改查</title>
  8. <link href="plugins/bootstrap-3.3.0/css/bootstrap.min.css" rel="stylesheet"/>
  9. <link href="plugins/material-design-iconic-font-2.2.0/css/material-design-iconic-font.min.css" rel="stylesheet"/>
  10. <link href="plugins/bootstrap-table-1.11.0/bootstrap-table.min.css" rel="stylesheet"/>
  11. <link href="plugins/waves-0.7.5/waves.min.css" rel="stylesheet"/>
  12. <link href="css/common.css" rel="stylesheet"/>
  13. </head>
  14. <body>
  15. <div id="main">
  16. <div id="toolbar">
  17. <a class="waves-effect waves-button" href="javascript:;"><i class="zmdi zmdi-plus"></i> 新增用户</a>
  18. <a class="waves-effect waves-button" href="javascript:;"><i class="zmdi zmdi-edit"></i> 编辑用户</a>
  19. <a class="waves-effect waves-button" href="javascript:;"><i class="zmdi zmdi-close"></i> 删除用户</a>
  20. </div>
  21. <table id="table"></table>
  22. </div>
  23. <script src="plugins/jquery.1.12.4.min.js"></script>
  24. <script src="plugins/bootstrap-3.3.0/js/bootstrap.min.js"></script>
  25. <script src="plugins/bootstrap-table-1.11.0/bootstrap-table.min.js"></script>
  26. <script src="plugins/bootstrap-table-1.11.0/locale/bootstrap-table-zh-CN.min.js"></script>
  27. <script src="plugins/waves-0.7.5/waves.min.js"></script>
  28. <script src="js/common.js"></script>
  29. <script>
  30. $(function() {
  31. // bootstrap table初始化
  32. $('#table').bootstrapTable({
  33. url: 'data/data1.json',
  34. height: getHeight(),
  35. striped: true,
  36. search: true,
  37. searchOnEnterKey: true,
  38. showRefresh: true,
  39. showToggle: true,
  40. showColumns: true,
  41. minimumCountColumns: 2,
  42. showPaginationSwitch: true,
  43. clickToSelect: true,
  44. detailView: true,
  45. detailFormatter: 'detailFormatter',
  46. pagination: true,
  47. paginationLoop: false,
  48. classes: 'table table-hover table-no-bordered',
  49. //sidePagination: 'server',
  50. idField: 'id',
  51. sortName: 'id',
  52. sortOrder: 'desc',
  53. toolbar: '#toolbar',
  54. columns: [
  55. {field: 'state', checkbox: true},
  56. {field: 'id', title: '编号', sortable: true, halign: 'center'},
  57. {field: 'username', title: '账号', sortable: true, halign: 'center'},
  58. {field: 'password', title: '密码', sortable: true, halign: 'center'},
  59. {field: 'name', title: '姓名', sortable: true, halign: 'center'},
  60. {field: 'sex', title: '性别', sortable: true, halign: 'center'},
  61. {field: 'age', title: '年龄', sortable: true, halign: 'center'},
  62. {field: 'phone', title: '手机', sortable: true, halign: 'center'},
  63. {field: 'email', title: '邮箱', sortable: true, halign: 'center'},
  64. {field: 'address', title: '地址', sortable: true, halign: 'center'},
  65. {field: 'remark', title: '备注', sortable: true, halign: 'center'},
  66. {field: 'action', title: '操作', halign: 'center', align: 'center', formatter: 'actionFormatter', events: 'actionEvents'}
  67. ]
  68. }).on('all.bs.table', function (e, name, args) {
  69. $('[data-toggle="tooltip"]').tooltip();
  70. $('[data-toggle="popover"]').popover();
  71. });
  72. $(window).resize(function () {
  73. $('#table').bootstrapTable('resetView', {
  74. height: getHeight()
  75. });
  76. });
  77. });
  78. function actionFormatter(value, row, index) {
  79. return [
  80. '<a class="like" href="javascript:void(0)" data-toggle="tooltip" title="Like"><i class="glyphicon glyphicon-heart"></i></a> ',
  81. '<a class="edit ml10" href="javascript:void(0)" data-toggle="tooltip" title="Edit"><i class="glyphicon glyphicon-edit"></i></a> ',
  82. '<a class="remove ml10" href="javascript:void(0)" data-toggle="tooltip" title="Remove"><i class="glyphicon glyphicon-remove"></i></a>'
  83. ].join('');
  84. }
  85. window.actionEvents = {
  86. 'click .like': function (e, value, row, index) {
  87. alert('You click like icon, row: ' + JSON.stringify(row));
  88. console.log(value, row, index);
  89. },
  90. 'click .edit': function (e, value, row, index) {
  91. alert('You click edit icon, row: ' + JSON.stringify(row));
  92. console.log(value, row, index);
  93. },
  94. 'click .remove': function (e, value, row, index) {
  95. alert('You click remove icon, row: ' + JSON.stringify(row));
  96. console.log(value, row, index);
  97. }
  98. };
  99. function detailFormatter(index, row) {
  100. var html = [];
  101. $.each(row, function (key, value) {
  102. html.push('<p><b>' + key + ':</b> ' + value + '</p>');
  103. });
  104. return html.join('');
  105. }
  106. function getHeight() {
  107. return $(window).height() - 20;
  108. }
  109. </script>
  110. </body>
  111. </html>