editable.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. <th:block th:include="include :: bootstrap-editable-css" />
  6. </head>
  7. <body class="gray-bg">
  8. <div class="container-div">
  9. <div class="btn-group-sm" id="toolbar" role="group">
  10. <a class="btn btn-info" onclick="getSelections()">
  11. <i class="fa fa-search"></i> 查询选择数据
  12. </a>
  13. <a class="btn btn-primary" onclick="getData()">
  14. <i class="fa fa-search"></i> 获取所有数据
  15. </a>
  16. </div>
  17. <div class="row">
  18. <div class="col-sm-12 select-table table-striped">
  19. <table id="bootstrap-table"></table>
  20. </div>
  21. </div>
  22. </div>
  23. <th:block th:include="include :: footer" />
  24. <th:block th:include="include :: bootstrap-table-editable-js" />
  25. <script th:inline="javascript">
  26. var prefix = ctx + "demo/table";
  27. var datas = [[${@dict.getType('sys_normal_disable')}]];
  28. $(function() {
  29. var options = {
  30. url: prefix + "/list",
  31. showSearch: false,
  32. showRefresh: false,
  33. showToggle: false,
  34. showColumns: false,
  35. showPageGo: true,
  36. onEditableSave: onEditableSave,
  37. columns: [{
  38. checkbox: true
  39. },
  40. {
  41. field : 'userId',
  42. title : '用户ID'
  43. },
  44. {
  45. field : 'userCode',
  46. title : '用户编号',
  47. editable: true
  48. },
  49. {
  50. field : 'userName',
  51. title : '用户姓名',
  52. editable : {
  53. type : 'text',
  54. title : '名称',
  55. emptytext : "【名称】为空",
  56. validate : function(value) {
  57. if (value.length > 30) {
  58. return '名称不能超过30个字符';
  59. }
  60. if (value.length == 0) {
  61. return '名称不能为空';
  62. }
  63. }
  64. }
  65. },
  66. {
  67. field : 'userPhone',
  68. title : '用户手机'
  69. },
  70. {
  71. field : 'userEmail',
  72. title : '用户邮箱'
  73. },
  74. {
  75. field : 'userBalance',
  76. title : '用户余额'
  77. },
  78. {
  79. field: 'status',
  80. title: '用户状态',
  81. align: 'center',
  82. editable : {
  83. type : 'select',
  84. title : '状态',
  85. source : [{
  86. value : 0,
  87. text : "正常"
  88. }, {
  89. value : 1,
  90. text : "停用"
  91. }]
  92. }
  93. },
  94. {
  95. title: '操作',
  96. align: 'center',
  97. formatter: function(value, row, index) {
  98. var actions = [];
  99. actions.push('<a class="btn btn-success btn-xs" href="#"><i class="fa fa-edit"></i>编辑</a> ');
  100. actions.push('<a class="btn btn-danger btn-xs" href="#"><i class="fa fa-remove"></i>删除</a>');
  101. return actions.join('');
  102. }
  103. }]
  104. };
  105. $.table.init(options);
  106. });
  107. function onEditableSave (field, row, rowIndex, oldValue, $el) {
  108. alert("字段名:" + field + ",当前值:" + row[field] + ",旧值:" + oldValue);
  109. }
  110. /* 查询表格所有数据值 */
  111. function getData(){
  112. var data = $("#" + table.options.id).bootstrapTable('getData');
  113. alert(JSON.stringify(data))
  114. }
  115. /* 查询表格选择行数据值 */
  116. function getSelections(){
  117. var data = $("#" + table.options.id).bootstrapTable('getSelections');
  118. alert(JSON.stringify(data))
  119. }
  120. </script>
  121. </body>
  122. </html>