print.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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="row">
  9. <div class="col-sm-12 select-table table-striped">
  10. <!-- data-show-print设置为true为显示工具栏上的“打印”按钮。
  11. data-print-as-filtered-and-sorted-on-ui为true时-在用户界面上按排序和过滤条件打印表格。请注意,如果设置为true以及用于过滤和排序的显式预定义打印选项(printFilter,printSortOrder,printSortColumn),则它们将应用于已由UI控件过滤和排序的数据。对于在UI上按过滤和排序方式打印数据-请勿设置以下3个选项:printFilter,printSortOrder,printSortColumn
  12. data-print-page-builder 接收html <table>元素作为字符串参数,返回html字符串进行打印。用于样式和添加页眉或页脚。
  13. data-print-sort-column 设置列字段名称以对打印表进行排序
  14. data-print-sort-order 有效值:“ asc”,“ desc”。仅当设置了printSortColumn时相关
  15. data-print-filter 设置值以按此列过滤打印的数据。
  16. data-print-formatter 函数(值,行,索引)-返回字符串。格式化打印表中此列的单元格值。函数行为类似于“ formatter”列选项
  17. printIgnore 设置为true可以在打印页面中隐藏此列。 -->
  18. <table id="bootstrap-table"></table>
  19. </div>
  20. </div>
  21. </div>
  22. <div th:include="include :: footer"></div>
  23. <th:block th:include="include :: bootstrap-table-print-js" />
  24. <script th:inline="javascript">
  25. var prefix = ctx + "demo/table";
  26. $(function() {
  27. var options = {
  28. url: prefix + "/list",
  29. showPrint: true,
  30. showSearch: false,
  31. showRefresh: false,
  32. showToggle: false,
  33. showColumns: false,
  34. printPageBuilder: printPageBuilder,
  35. columns: [{
  36. checkbox: true,
  37. printIgnore: true
  38. },
  39. {
  40. field : 'userId',
  41. title : '用户ID'
  42. },
  43. {
  44. field : 'userCode',
  45. title : '用户编号'
  46. },
  47. {
  48. field : 'userName',
  49. title : '用户姓名'
  50. },
  51. {
  52. field : 'userPhone',
  53. title : '用户手机'
  54. },
  55. {
  56. field : 'userEmail',
  57. title : '用户邮箱'
  58. },
  59. {
  60. field : 'userBalance',
  61. title : '用户余额'
  62. },
  63. {
  64. title: '操作',
  65. align: 'center',
  66. printIgnore: true,
  67. formatter: function(value, row, index) {
  68. var actions = [];
  69. actions.push('<a class="btn btn-danger btn-xs" href="javascript:;" onclick="remove(this)"><i class="fa fa-remove"></i>删除</a>');
  70. return actions.join('');
  71. }
  72. }]
  73. };
  74. $.table.init(options);
  75. });
  76. // 假删除操作
  77. function remove(obj) {
  78. $.modal.confirm("确认要删除吗?", function() {
  79. $(obj).parents("tr").remove();
  80. $.modal.msgSuccess('已删除!');
  81. });
  82. }
  83. // 自定义打印页面模板
  84. function printPageBuilder(table) {
  85. return `
  86. <html>
  87. <head>
  88. <style type="text/css" media="print">
  89. @page {
  90. size: auto;
  91. margin: 25px 0 25px 0;
  92. }
  93. </style>
  94. <style type="text/css" media="all">
  95. table {
  96. border-collapse: collapse;
  97. font-size: 12px;
  98. }
  99. table, th, td {
  100. border: 1px solid grey;
  101. }
  102. th, td {
  103. text-align: center;
  104. vertical-align: middle;
  105. }
  106. p {
  107. font-weight: bold;
  108. margin-left:20px;
  109. }
  110. table {
  111. width:94%;
  112. margin-left:3%;
  113. margin-right:3%;
  114. }
  115. div.bs-table-print {
  116. text-align:center;
  117. }
  118. </style>
  119. </head>
  120. <title>Print Table</title>
  121. <body>
  122. <div class="bs-table-print">${table}</div>
  123. </body>
  124. </html>`
  125. }
  126. </script>
  127. </body>
  128. </html>