Advertisement
Guest User

Untitled

a guest
May 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.39 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  5. <meta name="robots" content="noindex, nofollow">
  6. <meta name="googlebot" content="noindex, nofollow">
  7. <meta name="viewport" content="width=device-width, initial-scale=1">
  8. <script type="text/javascript" src="../node_modules/bootstrap-table/jquery.min.js"></script>
  9. <script type="text/javascript" src="../node_modules/bootstrap-table/boostrap4/js/popper.min.js"></script>
  10. <script type="text/javascript" src="../node_modules/bootstrap-table/boostrap4/js/bootstrap.min.js"></script>
  11. <link rel="stylesheet" type="text/css" href="../node_modules/bootstrap-table/bootstrap4/css/bootstrap.min.css">
  12. <link rel="stylesheet" type="text/css" href="../node_modules/bootstrap-table/bootstrap-table/src/bootstrap-table.css">
  13. <link rel="stylesheet" type="text/css" href="../node_modules/bootstrap-table/font-awesome/css/font-awesome.css">
  14. <script type="text/javascript" src="../node_modules/bootstrap-table/bootstrap-table/src/bootstrap-table.js"></script>
  15. <script type="text/javascript" src="../node_modules/bootstrap-table/bootstrap-table/src/extensions/export/bootstrap-table-export.js"></script>
  16. <script type="text/javascript" src="../node_modules/bootstrap-table/bootstrap-table/src/tableExport.js"></script>
  17. <style type="text/css">
  18. </style>
  19. <title>Datafus</title>
  20. </head>
  21.  
  22. <body>
  23. <div class="container">
  24. <h1>Datafus </h1>
  25. <div id="toolbar">
  26. <button id="remove" class="btn btn-danger" disabled>
  27. <i class="fa fa-remove"></i> Delete
  28. </button>
  29. </div>
  30. <table id="table"
  31. data-toolbar="#toolbar"
  32. data-search="true"
  33. data-show-refresh="true"
  34. data-show-toggle="true"
  35. data-show-columns="true"
  36. data-show-export="true"
  37. data-detail-view="true"
  38. data-detail-formatter="detailFormatter"
  39. data-minimum-count-columns="2"
  40. data-show-pagination-switch="true"
  41. data-pagination="true"
  42. data-id-field="id"
  43. data-page-list="[10, 25, 50, 100, ALL]"
  44. data-side-pagination="server"
  45. data-url="http://issues.wenzhixin.net.cn/examples/bootstrap_table/data"
  46. data-response-handler="responseHandler">
  47. </table>
  48. </div>
  49.  
  50. <script>
  51. const $table = $('#table');
  52. const $remove = $('#remove');
  53. let selections = [];
  54.  
  55. function initTable() {
  56. $table.bootstrapTable({
  57. height: getHeight(),
  58. columns: [
  59. [
  60. {
  61. field: 'state',
  62. checkbox: true,
  63. rowspan: 2,
  64. align: 'center',
  65. valign: 'middle'
  66. }, {
  67. title: 'Item ID',
  68. field: 'id',
  69. rowspan: 2,
  70. align: 'center',
  71. valign: 'middle',
  72. sortable: true
  73. }, {
  74. title: 'Item Detail',
  75. colspan: 3,
  76. align: 'center'
  77. }
  78. ],
  79. [
  80. {
  81. field: 'name',
  82. title: 'Item Name',
  83. sortable: true,
  84. editable: true,
  85. align: 'center'
  86. }, {
  87. field: 'price',
  88. title: 'Item Price',
  89. sortable: true,
  90. align: 'center',
  91. editable: {
  92. type: 'text',
  93. title: 'Item Price',
  94. validate(value) {
  95. value = $.trim(value);
  96. if (!value) {
  97. return 'This field is required';
  98. }
  99. if (!/^\$/.test(value)) {
  100. return 'This field needs to start width $.'
  101. }
  102. const data = $table.bootstrapTable('getData');
  103. const index = $(this).parents('tr').data('index');
  104. console.log(data[index]);
  105. return '';
  106. }
  107. },
  108. footerFormatter: totalPriceFormatter
  109. }, {
  110. field: 'operate',
  111. title: 'Item Operate',
  112. align: 'center',
  113. events: operateEvents,
  114. formatter: operateFormatter
  115. }
  116. ]
  117. ]
  118. });
  119. // sometimes footer render error.
  120. setTimeout(() => {
  121. $table.bootstrapTable('resetView');
  122. }, 200);
  123. $table.on('check.bs.table uncheck.bs.table ' +
  124. 'check-all.bs.table uncheck-all.bs.table', () => {
  125. $remove.prop('disabled', !$table.bootstrapTable('getSelections').length);
  126.  
  127. // save your data, here just save the current page
  128. selections = getIdSelections();
  129. // push or splice the selections if you want to save all data selections
  130. });
  131. $table.on('expand-row.bs.table', (e, index, row, $detail) => {
  132. if (index % 2 == 1) {
  133. $detail.html('Loading from ajax request...');
  134. $.get('LICENSE', res => {
  135. $detail.html(res.replace(/\n/g, '<br>'));
  136. });
  137. }
  138. });
  139. $table.on('all.bs.table', (e, name, args) => {
  140. console.log(name, args);
  141. });
  142. $remove.click(() => {
  143. const ids = getIdSelections();
  144. $table.bootstrapTable('remove', {
  145. field: 'id',
  146. values: ids
  147. });
  148. $remove.prop('disabled', true);
  149. });
  150. $(window).resize(() => {
  151. $table.bootstrapTable('resetView', {
  152. height: getHeight()
  153. });
  154. });
  155. }
  156.  
  157.  
  158.  
  159. function getIdSelections() {
  160. return $.map($table.bootstrapTable('getSelections'), ({id}) => id);
  161. }
  162.  
  163. function responseHandler(res) {
  164. $.each(res.rows, (i, row) => {
  165. row.state = $.inArray(row.id, selections) !== -1;
  166. });
  167. return res;
  168. }
  169.  
  170. function detailFormatter(index, row) {
  171. const html = [];
  172. $.each(row, (key, value) => {
  173. html.push(`<p><b>${key}:</b> ${value}</p>`);
  174. });
  175. return html.join('');
  176. }
  177.  
  178. function operateFormatter(value, row, index) {
  179. return [
  180. '<a class="like" href="javascript:void(0)" title="Like">',
  181. '<i class="fa fa-heart"></i>',
  182. '</a> ',
  183. '<a class="remove" href="javascript:void(0)" title="Remove">',
  184. '<i class="fa fa-remove"></i>',
  185. '</a>'
  186. ].join('');
  187. }
  188.  
  189. window.operateEvents = {
  190. 'click .like': function (e, value, row, index) {
  191. alert(`You click like action, row: ${JSON.stringify(row)}`);
  192. },
  193. 'click .remove': function(e, value, {id}, index) {
  194. $table.bootstrapTable('remove', {
  195. field: 'id',
  196. values: [id]
  197. });
  198. }
  199. };
  200.  
  201. function totalPriceFormatter(data) {
  202. let total = 0;
  203. $.each(data, (i, {price}) => {
  204. total += +(price.substring(1));
  205. });
  206. return `$${total}`;
  207. }
  208.  
  209. function getHeight() {
  210. return $(window).height() - $('h1').outerHeight(true);
  211. }
  212.  
  213. $(() => {
  214. initTable();
  215. })
  216. </script>
  217. </body>
  218. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement