|
@@ -0,0 +1,71 @@
|
|
|
|
|
+/**
|
|
|
|
|
+ * @author zhixin wen <wenzhixin2010@gmail.com>
|
|
|
|
|
+ * extensions: https://github.com/kayalshri/tableExport.jquery.plugin
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+(function ($) {
|
|
|
|
|
+ 'use strict';
|
|
|
|
|
+
|
|
|
|
|
+ var TYPE_NAME = {
|
|
|
|
|
+ json: 'JSON',
|
|
|
|
|
+ xml: 'XML',
|
|
|
|
|
+ png: 'PNG',
|
|
|
|
|
+ csv: 'CSV',
|
|
|
|
|
+ txt: 'TXT',
|
|
|
|
|
+ sql: 'SQL',
|
|
|
|
|
+ doc: 'MS-Word',
|
|
|
|
|
+ excel: 'Ms-Excel',
|
|
|
|
|
+ powerpoint: 'Ms-Powerpoint',
|
|
|
|
|
+ pdf: 'PDF'
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ $.extend($.fn.bootstrapTable.defaults, {
|
|
|
|
|
+ showExport: true,
|
|
|
|
|
+ // 'json', 'xml', 'png', 'csv', 'txt', 'sql', 'doc', 'excel', 'powerpoint', 'pdf'
|
|
|
|
|
+ exportTypes: ['json', 'xml', 'csv', 'txt', 'sql', 'excel']
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ var BootstrapTable = $.fn.bootstrapTable.Constructor,
|
|
|
|
|
+ _initToolbar = BootstrapTable.prototype.initToolbar;
|
|
|
|
|
+
|
|
|
|
|
+ BootstrapTable.prototype.initToolbar = function () {
|
|
|
|
|
+ _initToolbar.apply(this, Array.prototype.slice.apply(arguments));
|
|
|
|
|
+
|
|
|
|
|
+ if (this.options.showExport) {
|
|
|
|
|
+ var that = this,
|
|
|
|
|
+ $btnGroup = this.$toolbar.find('>.btn-group'),
|
|
|
|
|
+ $export = $btnGroup.find('div.export');
|
|
|
|
|
+
|
|
|
|
|
+ if (!$export.length) {
|
|
|
|
|
+ $export = $([
|
|
|
|
|
+ '<div class="export btn-group">',
|
|
|
|
|
+ '<button class="btn btn-default dropdown-toggle" ' +
|
|
|
|
|
+ 'data-toggle="dropdown" type="button">',
|
|
|
|
|
+ '<i class="glyphicon glyphicon-export icon-export"></i> ',
|
|
|
|
|
+ '<span class="caret"></span>',
|
|
|
|
|
+ '</button>',
|
|
|
|
|
+ '<ul class="dropdown-menu" role="menu">',
|
|
|
|
|
+ '</ul>',
|
|
|
|
|
+ '</div>'].join('')).appendTo($btnGroup);
|
|
|
|
|
+
|
|
|
|
|
+ var $menu = $export.find('.dropdown-menu');
|
|
|
|
|
+ $.each(this.options.exportTypes, function (i, type) {
|
|
|
|
|
+ if (TYPE_NAME.hasOwnProperty(type)) {
|
|
|
|
|
+ $menu.append(['<li data-type="' + type + '">',
|
|
|
|
|
+ '<a href="javascript:void(0)">',
|
|
|
|
|
+ TYPE_NAME[type],
|
|
|
|
|
+ '</a>',
|
|
|
|
|
+ '</li>'].join(''));
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ $menu.find('li').click(function () {
|
|
|
|
|
+ that.$el.tableExport({
|
|
|
|
|
+ type: $(this).data('type'),
|
|
|
|
|
+ escape: false
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+})(jQuery);
|