reorderRows.html 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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-primary" onclick="getData()">
  10. <i class="fa fa-search"></i> 查询所有数据
  11. </a>
  12. </div>
  13. <div class="row">
  14. <div class="col-sm-12 select-table table-striped">
  15. <p class="select-title">按住表格行拖拽</p>
  16. <table id="bootstrap-table"
  17. data-use-row-attr-func="true"
  18. data-reorderable-rows="true"></table>
  19. </div>
  20. </div>
  21. </div>
  22. <div th:include="include :: footer"></div>
  23. <th:block th:include="include :: bootstrap-table-reorder-rows-js" />
  24. <script th:inline="javascript">
  25. var prefix = ctx + "demo/table";
  26. var datas = [[${@dict.getType('sys_normal_disable')}]];
  27. $(function() {
  28. var options = {
  29. url: prefix + "/list",
  30. showSearch: false,
  31. showRefresh: false,
  32. showToggle: false,
  33. showColumns: false,
  34. onReorderRow: function (data, newRow, oldRow, el) {
  35. // 当拖拽结束后,data为整个表格的数据
  36. console.table(data)
  37. // 当sidePagination: "server"时,拖拽行后顺序错乱,需要重新调用加载数据方法
  38. $("#" + table.options.id).bootstrapTable('load', {
  39. total: el._xhr.responseJSON.total,
  40. rows: data
  41. });
  42. return false;
  43. },
  44. columns: [{
  45. checkbox: true
  46. },
  47. {
  48. field : 'userId',
  49. title : '用户ID'
  50. },
  51. {
  52. field : 'userCode',
  53. title : '用户编号'
  54. },
  55. {
  56. field : 'userName',
  57. title : '用户姓名'
  58. },
  59. {
  60. field : 'userPhone',
  61. title : '用户手机'
  62. },
  63. {
  64. field : 'userEmail',
  65. title : '用户邮箱'
  66. },
  67. {
  68. field : 'userBalance',
  69. title : '用户余额'
  70. },
  71. {
  72. field: 'status',
  73. title: '用户状态',
  74. align: 'center',
  75. formatter: function(value, row, index) {
  76. return $.table.selectDictLabel(datas, value);
  77. }
  78. }]
  79. };
  80. $.table.init(options);
  81. });
  82. /* 查询表格所有数据值 */
  83. function getData(){
  84. var data = $("#" + table.options.id).bootstrapTable('getData');
  85. alert(JSON.stringify(data.map( item => { return item.userId })))
  86. }
  87. </script>
  88. </body>
  89. </html>