curd.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <!DOCTYPE html>
  2. <html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
  3. <head>
  4. <th:block th:include="include :: header('动态增删改查')" />
  5. </head>
  6. <body class="gray-bg">
  7. <div class="container-div">
  8. <div class="btn-group-sm" id="toolbar" role="group">
  9. <a class="btn btn-success" onclick="insertRow()">
  10. <i class="fa fa-plus"></i> 新增行
  11. </a>
  12. <a class="btn btn-danger multiple disabled" onclick="removeRow()">
  13. <i class="fa fa-remove"></i> 删除选择行
  14. </a>
  15. <a class="btn btn-danger" onclick="removeRowByUniqueId()">
  16. <i class="fa fa-remove"></i> 根据值删除行
  17. </a>
  18. <a class="btn btn-danger" onclick="removeRowAll()">
  19. <i class="fa fa-remove"></i> 删除所有行
  20. </a>
  21. <a class="btn btn-info" onclick="updateRow()">
  22. <i class="fa fa-edit"></i> 修改行
  23. </a>
  24. <a class="btn btn-info" onclick="updateRowByUniqueId()">
  25. <i class="fa fa-edit"></i> 根据值修改行
  26. </a>
  27. <a class="btn btn-info" onclick="getSelections()">
  28. <i class="fa fa-search"></i> 查询选择数据
  29. </a>
  30. <a class="btn btn-info" onclick="getRowByUniqueId()">
  31. <i class="fa fa-search"></i> 根据值查询行
  32. </a>
  33. <a class="btn btn-primary" onclick="getData()">
  34. <i class="fa fa-search"></i> 查询所有数据
  35. </a>
  36. </div>
  37. <div class="row">
  38. <div class="col-sm-12 select-table table-striped">
  39. <table id="bootstrap-table"></table>
  40. </div>
  41. </div>
  42. </div>
  43. <div th:include="include :: footer"></div>
  44. <script th:inline="javascript">
  45. var prefix = ctx + "demo/table";
  46. $(function() {
  47. var options = {
  48. url: prefix + "/list",
  49. showSearch: false,
  50. showRefresh: false,
  51. showToggle: false,
  52. showColumns: false,
  53. pagination: false,
  54. uniqueId: "userId",
  55. height: 400,
  56. columns: [{
  57. checkbox: true
  58. },
  59. {
  60. field : 'userId',
  61. title : '用户ID'
  62. },
  63. {
  64. field : 'userCode',
  65. title : '用户编号'
  66. },
  67. {
  68. field : 'userName',
  69. title : '用户姓名'
  70. },
  71. {
  72. field : 'userPhone',
  73. title : '用户手机'
  74. },
  75. {
  76. field : 'userEmail',
  77. title : '用户邮箱'
  78. },
  79. {
  80. field : 'userBalance',
  81. title : '用户余额'
  82. }]
  83. };
  84. $.table.init(options);
  85. });
  86. /* 新增表格行 */
  87. function insertRow(){
  88. var randomId = 100 + ~~(Math.random() * 100)
  89. $("#" + table.options.id).bootstrapTable('insertRow', {
  90. index: 0, // 你想插入到哪,0表示第一行
  91. row: {
  92. userId: randomId,
  93. userCode: 2000000 + randomId,
  94. userName: '测试' + randomId,
  95. userPhone: '1588888888',
  96. userEmail: 'ry1@qq.com',
  97. userBalance: 10 + randomId,
  98. }
  99. })
  100. }
  101. /* 删除指定表格行 */
  102. function removeRow(){
  103. var ids = $.table.selectColumns("userId");
  104. if (ids.length == 0) {
  105. $.modal.alertWarning("请至少选择一条记录");
  106. return;
  107. }
  108. $("#" + table.options.id).bootstrapTable('remove', {
  109. field: 'userId',
  110. values: ids
  111. })
  112. }
  113. /* 删除行ID值为1的数据 */
  114. function removeRowByUniqueId(){
  115. $("#" + table.options.id).bootstrapTable('removeByUniqueId', 1)
  116. }
  117. /* 删除所有表格行 */
  118. function removeRowAll(){
  119. $("#" + table.options.id).bootstrapTable('removeAll')
  120. }
  121. /* 修改表格行 */
  122. function updateRow(){
  123. var randomId = 100 + ~~(Math.random() * 100)
  124. $("#" + table.options.id).bootstrapTable('updateRow', {
  125. index: 0, // 你想修改哪行,0表示第一行
  126. row: {
  127. userId: randomId,
  128. userCode: 3000000 + randomId,
  129. userName: '测试' + randomId,
  130. userPhone: '1599999999',
  131. userEmail: 'ry2@qq.com',
  132. userBalance: 50 + randomId,
  133. }
  134. })
  135. }
  136. /* 修改行ID值为1的数据 */
  137. function updateRowByUniqueId(){
  138. var randomId = 100 + ~~(Math.random() * 100)
  139. $("#" + table.options.id).bootstrapTable('updateByUniqueId', {
  140. id: 1,
  141. row: {
  142. userId: randomId,
  143. userCode: 3000000 + randomId,
  144. userName: '测试' + randomId,
  145. userPhone: '1599999999',
  146. userEmail: 'ry2@qq.com',
  147. userBalance: 50 + randomId,
  148. }
  149. })
  150. }
  151. /* 查询表格所有数据值 */
  152. function getData(){
  153. var data = $("#" + table.options.id).bootstrapTable('getData');
  154. alert(JSON.stringify(data))
  155. }
  156. /* 查询行ID值为1的数据 */
  157. function getRowByUniqueId(){
  158. var data = $("#" + table.options.id).bootstrapTable('getRowByUniqueId', 1);
  159. alert(JSON.stringify(data))
  160. }
  161. /* 查询表格选择行数据值 */
  162. function getSelections(){
  163. var data = $("#" + table.options.id).bootstrapTable('getSelections');
  164. alert(JSON.stringify(data))
  165. }
  166. </script>
  167. </body>
  168. </html>