1 | (function (global, factory) {
|
2 | if (typeof define === "function" && define.amd) {
|
3 | define([], factory);
|
4 | } else if (typeof exports !== "undefined") {
|
5 | factory();
|
6 | } else {
|
7 | var mod = {
|
8 | exports: {}
|
9 | };
|
10 | factory();
|
11 | global.bootstrapTableExport = mod.exports;
|
12 | }
|
13 | })(this, function () {
|
14 | 'use strict';
|
15 |
|
16 | function _defineProperty(obj, key, value) {
|
17 | if (key in obj) {
|
18 | Object.defineProperty(obj, key, {
|
19 | value: value,
|
20 | enumerable: true,
|
21 | configurable: true,
|
22 | writable: true
|
23 | });
|
24 | } else {
|
25 | obj[key] = value;
|
26 | }
|
27 |
|
28 | return obj;
|
29 | }
|
30 |
|
31 | function _classCallCheck(instance, Constructor) {
|
32 | if (!(instance instanceof Constructor)) {
|
33 | throw new TypeError("Cannot call a class as a function");
|
34 | }
|
35 | }
|
36 |
|
37 | var _createClass = function () {
|
38 | function defineProperties(target, props) {
|
39 | for (var i = 0; i < props.length; i++) {
|
40 | var descriptor = props[i];
|
41 | descriptor.enumerable = descriptor.enumerable || false;
|
42 | descriptor.configurable = true;
|
43 | if ("value" in descriptor) descriptor.writable = true;
|
44 | Object.defineProperty(target, descriptor.key, descriptor);
|
45 | }
|
46 | }
|
47 |
|
48 | return function (Constructor, protoProps, staticProps) {
|
49 | if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
50 | if (staticProps) defineProperties(Constructor, staticProps);
|
51 | return Constructor;
|
52 | };
|
53 | }();
|
54 |
|
55 | function _possibleConstructorReturn(self, call) {
|
56 | if (!self) {
|
57 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
58 | }
|
59 |
|
60 | return call && (typeof call === "object" || typeof call === "function") ? call : self;
|
61 | }
|
62 |
|
63 | var _get = function get(object, property, receiver) {
|
64 | if (object === null) object = Function.prototype;
|
65 | var desc = Object.getOwnPropertyDescriptor(object, property);
|
66 |
|
67 | if (desc === undefined) {
|
68 | var parent = Object.getPrototypeOf(object);
|
69 |
|
70 | if (parent === null) {
|
71 | return undefined;
|
72 | } else {
|
73 | return get(parent, property, receiver);
|
74 | }
|
75 | } else if ("value" in desc) {
|
76 | return desc.value;
|
77 | } else {
|
78 | var getter = desc.get;
|
79 |
|
80 | if (getter === undefined) {
|
81 | return undefined;
|
82 | }
|
83 |
|
84 | return getter.call(receiver);
|
85 | }
|
86 | };
|
87 |
|
88 | function _inherits(subClass, superClass) {
|
89 | if (typeof superClass !== "function" && superClass !== null) {
|
90 | throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
91 | }
|
92 |
|
93 | subClass.prototype = Object.create(superClass && superClass.prototype, {
|
94 | constructor: {
|
95 | value: subClass,
|
96 | enumerable: false,
|
97 | writable: true,
|
98 | configurable: true
|
99 | }
|
100 | });
|
101 | if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
|
102 | }
|
103 |
|
104 | |
105 |
|
106 |
|
107 |
|
108 |
|
109 | (function ($) {
|
110 | var Utils = $.fn.bootstrapTable.utils;
|
111 |
|
112 | var bootstrap = {
|
113 | 3: {
|
114 | icons: {
|
115 | export: 'glyphicon-export icon-share'
|
116 | },
|
117 | html: {
|
118 | dropmenu: '<ul class="dropdown-menu" role="menu"></ul>',
|
119 | dropitem: '<li role="menuitem" data-type="%s"><a href="javascript:">%s</a></li>'
|
120 | }
|
121 | },
|
122 | 4: {
|
123 | icons: {
|
124 | export: 'fa-download'
|
125 | },
|
126 | html: {
|
127 | dropmenu: '<div class="dropdown-menu dropdown-menu-right"></div>',
|
128 | dropitem: '<a class="dropdown-item" data-type="%s" href="javascript:">%s</a>'
|
129 | }
|
130 | }
|
131 | }[Utils.bootstrapVersion];
|
132 |
|
133 | var TYPE_NAME = {
|
134 | json: 'JSON',
|
135 | xml: 'XML',
|
136 | png: 'PNG',
|
137 | csv: 'CSV',
|
138 | txt: 'TXT',
|
139 | sql: 'SQL',
|
140 | doc: 'MS-Word',
|
141 | excel: 'MS-Excel',
|
142 | xlsx: 'MS-Excel (OpenXML)',
|
143 | powerpoint: 'MS-Powerpoint',
|
144 | pdf: 'PDF'
|
145 | };
|
146 |
|
147 | $.extend($.fn.bootstrapTable.defaults, {
|
148 | showExport: false,
|
149 | exportDataType: 'basic',
|
150 | exportTypes: ['json', 'xml', 'csv', 'txt', 'sql', 'excel'],
|
151 | exportOptions: {},
|
152 | exportFooter: false
|
153 | });
|
154 |
|
155 | $.extend($.fn.bootstrapTable.defaults.icons, {
|
156 | export: bootstrap.icons.export
|
157 | });
|
158 |
|
159 | $.extend($.fn.bootstrapTable.locales, {
|
160 | formatExport: function formatExport() {
|
161 | return 'Export data';
|
162 | }
|
163 | });
|
164 | $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales);
|
165 |
|
166 | $.fn.bootstrapTable.methods.push('exportTable');
|
167 |
|
168 | $.BootstrapTable = function (_$$BootstrapTable) {
|
169 | _inherits(_class, _$$BootstrapTable);
|
170 |
|
171 | function _class() {
|
172 | _classCallCheck(this, _class);
|
173 |
|
174 | return _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).apply(this, arguments));
|
175 | }
|
176 |
|
177 | _createClass(_class, [{
|
178 | key: 'initToolbar',
|
179 | value: function initToolbar() {
|
180 | var _this2 = this;
|
181 |
|
182 | var o = this.options;
|
183 |
|
184 | this.showToolbar = this.showToolbar || o.showExport;
|
185 |
|
186 | _get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), 'initToolbar', this).call(this);
|
187 |
|
188 | if (!this.options.showExport) {
|
189 | return;
|
190 | }
|
191 | var $btnGroup = this.$toolbar.find('>.btn-group');
|
192 | this.$export = $btnGroup.find('div.export');
|
193 |
|
194 | if (this.$export.length) {
|
195 | this.updateExportButton();
|
196 | return;
|
197 | }
|
198 | this.$export = $('\n <div class="export btn-group">\n <button class="btn btn-' + o.buttonsClass + ' btn-' + o.iconSize + ' dropdown-toggle"\n aria-label="export type"\n title="' + o.formatExport() + '"\n data-toggle="dropdown"\n type="button">\n <i class="' + o.iconsPrefix + ' ' + o.icons.export + '"></i>\n <span class="caret"></span>\n </button>\n ' + bootstrap.html.dropmenu + '\n </div>\n ').appendTo($btnGroup);
|
199 |
|
200 | this.updateExportButton();
|
201 |
|
202 | var $menu = this.$export.find('.dropdown-menu');
|
203 | var exportTypes = o.exportTypes;
|
204 |
|
205 | if (typeof exportTypes === 'string') {
|
206 | var types = exportTypes.slice(1, -1).replace(/ /g, '').split(',');
|
207 | exportTypes = types.map(function (t) {
|
208 | return t.slice(1, -1);
|
209 | });
|
210 | }
|
211 | for (var _iterator = exportTypes, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
212 | var _ref;
|
213 |
|
214 | if (_isArray) {
|
215 | if (_i >= _iterator.length) break;
|
216 | _ref = _iterator[_i++];
|
217 | } else {
|
218 | _i = _iterator.next();
|
219 | if (_i.done) break;
|
220 | _ref = _i.value;
|
221 | }
|
222 |
|
223 | var type = _ref;
|
224 |
|
225 | if (TYPE_NAME.hasOwnProperty(type)) {
|
226 | $menu.append(Utils.sprintf(bootstrap.html.dropitem, type, TYPE_NAME[type]));
|
227 | }
|
228 | }
|
229 |
|
230 | $menu.find('>li, >a').click(function (_ref2) {
|
231 | var currentTarget = _ref2.currentTarget;
|
232 |
|
233 | var type = $(currentTarget).data('type');
|
234 | var exportOptions = {
|
235 | type: type,
|
236 | escape: false
|
237 | };
|
238 |
|
239 | _this2.exportTable(exportOptions);
|
240 | });
|
241 | }
|
242 | }, {
|
243 | key: 'exportTable',
|
244 | value: function exportTable(options) {
|
245 | var _this3 = this;
|
246 |
|
247 | var o = this.options;
|
248 | var stateField = this.header.stateField;
|
249 | var isCardView = o.cardView;
|
250 |
|
251 | var doExport = function doExport(callback) {
|
252 | if (stateField) {
|
253 | _this3.hideColumn(stateField);
|
254 | }
|
255 | if (isCardView) {
|
256 | _this3.toggleView();
|
257 | }
|
258 |
|
259 | var data = _this3.getData();
|
260 | if (o.exportFooter) {
|
261 | var $footerRow = _this3.$tableFooter.find('tr').first();
|
262 | var footerData = {};
|
263 | var footerHtml = [];
|
264 |
|
265 | $.each($footerRow.children(), function (index, footerCell) {
|
266 | var footerCellHtml = $(footerCell).children('.th-inner').first().html();
|
267 | footerData[_this3.columns[index].field] = footerCellHtml === ' ' ? null : footerCellHtml;
|
268 |
|
269 |
|
270 | footerHtml.push(footerCellHtml);
|
271 | });
|
272 |
|
273 | _this3.append(footerData);
|
274 |
|
275 | var $lastTableRow = _this3.$body.children().last();
|
276 |
|
277 | $.each($lastTableRow.children(), function (index, lastTableRowCell) {
|
278 | $(lastTableRowCell).html(footerHtml[index]);
|
279 | });
|
280 | }
|
281 |
|
282 | _this3.$el.tableExport($.extend({
|
283 | onAfterSaveToFile: function onAfterSaveToFile() {
|
284 | if (o.exportFooter) {
|
285 | _this3.load(data);
|
286 | }
|
287 |
|
288 | if (stateField) {
|
289 | _this3.showColumn(stateField);
|
290 | }
|
291 | if (isCardView) {
|
292 | _this3.toggleView();
|
293 | }
|
294 |
|
295 | callback();
|
296 | }
|
297 | }, o.exportOptions, options));
|
298 | };
|
299 |
|
300 | if (o.exportDataType === 'all' && o.pagination) {
|
301 | var eventName = o.sidePagination === 'server' ? 'post-body.bs.table' : 'page-change.bs.table';
|
302 | this.$el.one(eventName, function () {
|
303 | doExport(function () {
|
304 | _this3.togglePagination();
|
305 | });
|
306 | });
|
307 | this.togglePagination();
|
308 | } else if (o.exportDataType === 'selected') {
|
309 | var data = this.getData();
|
310 | var selectedData = this.getSelections();
|
311 | if (!selectedData.length) {
|
312 | return;
|
313 | }
|
314 |
|
315 | if (o.sidePagination === 'server') {
|
316 | data = _defineProperty({
|
317 | total: o.totalRows
|
318 | }, this.options.dataField, data);
|
319 | selectedData = _defineProperty({
|
320 | total: selectedData.length
|
321 | }, this.options.dataField, selectedData);
|
322 | }
|
323 |
|
324 | this.load(selectedData);
|
325 | doExport(function () {
|
326 | _this3.load(data);
|
327 | });
|
328 | } else {
|
329 | doExport();
|
330 | }
|
331 | }
|
332 | }, {
|
333 | key: 'updateSelected',
|
334 | value: function updateSelected() {
|
335 | _get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), 'updateSelected', this).call(this);
|
336 | this.updateExportButton();
|
337 | }
|
338 | }, {
|
339 | key: 'updateExportButton',
|
340 | value: function updateExportButton() {
|
341 | if (this.options.exportDataType === 'selected') {
|
342 | this.$export.find('> button').prop('disabled', !this.getSelections().length);
|
343 | }
|
344 | }
|
345 | }]);
|
346 |
|
347 | return _class;
|
348 | }($.BootstrapTable);
|
349 | })(jQuery);
|
350 | }); |
\ | No newline at end of file |