ckt的看板部分
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
5.1 KiB

4 years ago
  1. /**
  2. * @author zhixin wen <wenzhixin2010@gmail.com>
  3. * extensions: https://github.com/kayalshri/tableExport.jquery.plugin
  4. */
  5. (function ($) {
  6. 'use strict';
  7. var sprintf = $.fn.bootstrapTable.utils.sprintf;
  8. var TYPE_NAME = {
  9. json: 'JSON',
  10. xml: 'XML',
  11. png: 'PNG',
  12. csv: 'CSV',
  13. txt: 'TXT',
  14. sql: 'SQL',
  15. doc: 'MS-Word',
  16. excel: '导出xls',
  17. xlsx: '导出xlsx',
  18. /*xlsx: 'MS-Excel (OpenXML)',*/
  19. powerpoint: 'MS-Powerpoint',
  20. pdf: 'PDF'
  21. };
  22. $.extend($.fn.bootstrapTable.defaults, {
  23. showExport: false,
  24. exportDataType: 'basic', // basic, all, selected
  25. // 'json', 'xml', 'png', 'csv', 'txt', 'sql', 'doc', 'excel', 'powerpoint', 'pdf'
  26. exportTypes: ['json', 'xml', 'csv', 'txt', 'sql', 'excel','xlsx'],
  27. exportOptions: {}
  28. });
  29. $.extend($.fn.bootstrapTable.defaults.icons, {
  30. export: 'glyphicon-export icon-share'
  31. });
  32. $.extend($.fn.bootstrapTable.locales, {
  33. formatExport: function () {
  34. return 'Export data';
  35. }
  36. });
  37. $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales);
  38. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  39. _initToolbar = BootstrapTable.prototype.initToolbar;
  40. BootstrapTable.prototype.initToolbar = function () {
  41. this.showToolbar = this.options.showExport;
  42. _initToolbar.apply(this, Array.prototype.slice.apply(arguments));
  43. if (this.options.showExport) {
  44. var that = this,
  45. $btnGroup = this.$toolbar.find('>.btn-group'),
  46. $export = $btnGroup.find('div.export');
  47. if (!$export.length) {
  48. $export = $([
  49. '<div class="export btn-group">',
  50. '<button class="btn' +
  51. sprintf(' btn-%s', this.options.buttonsClass) +
  52. sprintf(' btn-%s', this.options.iconSize) +
  53. ' dropdown-toggle" aria-label="export type" ' +
  54. 'title="' + this.options.formatExport() + '" ' +
  55. 'data-toggle="dropdown" type="button">',
  56. sprintf('<i class="%s %s"></i> ', this.options.iconsPrefix, this.options.icons.export),
  57. '<span class="caret"></span>',
  58. '</button>',
  59. '<ul class="dropdown-menu" role="menu">',
  60. '</ul>',
  61. '</div>'].join('')).appendTo($btnGroup);
  62. var $menu = $export.find('.dropdown-menu'),
  63. exportTypes = this.options.exportTypes;
  64. if (typeof this.options.exportTypes === 'string') {
  65. var types = this.options.exportTypes.slice(1, -1).replace(/ /g, '').split(',');
  66. exportTypes = [];
  67. $.each(types, function (i, value) {
  68. exportTypes.push(value.slice(1, -1));
  69. });
  70. }
  71. $.each(exportTypes, function (i, type) {
  72. if (TYPE_NAME.hasOwnProperty(type)) {
  73. $menu.append(['<li role="menuitem" data-type="' + type + '">',
  74. '<a href="javascript:void(0)">',
  75. TYPE_NAME[type],
  76. '</a>',
  77. '</li>'].join(''));
  78. }
  79. });
  80. $menu.find('li').click(function () {
  81. var type = $(this).data('type'),
  82. doExport = function () {
  83. that.$el.tableExport($.extend({}, that.options.exportOptions, {
  84. type: type,
  85. escape: false
  86. }));
  87. };
  88. if (that.options.exportDataType === 'all' && that.options.pagination) {
  89. that.$el.one(that.options.sidePagination === 'server' ? 'post-body.bs.table' : 'page-change.bs.table', function () {
  90. doExport();
  91. that.togglePagination();
  92. });
  93. that.togglePagination();
  94. } else if (that.options.exportDataType === 'selected') {
  95. var data = that.getData(),
  96. selectedData = that.getAllSelections();
  97. // Quick fix #2220
  98. if (that.options.sidePagination === 'server') {
  99. data = {total: that.options.totalRows};
  100. data[that.options.dataField] = that.getData();
  101. selectedData = {total: that.options.totalRows};
  102. selectedData[that.options.dataField] = that.getAllSelections();
  103. }
  104. that.load(selectedData);
  105. doExport();
  106. that.load(data);
  107. } else {
  108. doExport();
  109. }
  110. });
  111. }
  112. }
  113. };
  114. })(jQuery);