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 | var $export = $btnGroup.find('div.export');
|
193 |
|
194 | if ($export.length) {
|
195 | return;
|
196 | }
|
197 | $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);
|
198 |
|
199 | var $menu = $export.find('.dropdown-menu');
|
200 | var exportTypes = o.exportTypes;
|
201 |
|
202 | if (typeof exportTypes === 'string') {
|
203 | var types = exportTypes.slice(1, -1).replace(/ /g, '').split(',');
|
204 | exportTypes = types.map(function (t) {
|
205 | return t.slice(1, -1);
|
206 | });
|
207 | }
|
208 | var _iteratorNormalCompletion = true;
|
209 | var _didIteratorError = false;
|
210 | var _iteratorError = undefined;
|
211 |
|
212 | try {
|
213 | for (var _iterator = exportTypes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
214 | var type = _step.value;
|
215 |
|
216 | if (TYPE_NAME.hasOwnProperty(type)) {
|
217 | $menu.append(Utils.sprintf(bootstrap.html.dropitem, type, TYPE_NAME[type]));
|
218 | }
|
219 | }
|
220 | } catch (err) {
|
221 | _didIteratorError = true;
|
222 | _iteratorError = err;
|
223 | } finally {
|
224 | try {
|
225 | if (!_iteratorNormalCompletion && _iterator.return) {
|
226 | _iterator.return();
|
227 | }
|
228 | } finally {
|
229 | if (_didIteratorError) {
|
230 | throw _iteratorError;
|
231 | }
|
232 | }
|
233 | }
|
234 |
|
235 | $menu.find('>li, >a').click(function (_ref) {
|
236 | var currentTarget = _ref.currentTarget;
|
237 |
|
238 | var type = $(currentTarget).data('type');
|
239 | var exportOptions = {
|
240 | type: type,
|
241 | escape: false
|
242 | };
|
243 |
|
244 | _this2.exportTable(exportOptions);
|
245 | });
|
246 | }
|
247 | }, {
|
248 | key: 'exportTable',
|
249 | value: function exportTable(options) {
|
250 | var _this3 = this;
|
251 |
|
252 | var o = this.options;
|
253 |
|
254 | var doExport = function doExport() {
|
255 | var that = _this3;
|
256 | var data = _this3.getData();
|
257 | if (o.exportFooter) {
|
258 | var $footerRow = _this3.$tableFooter.find('tr').first();
|
259 | var footerData = {};
|
260 | var footerHtml = [];
|
261 |
|
262 | $.each($footerRow.children(), function (index, footerCell) {
|
263 | var footerCellHtml = $(footerCell).children('.th-inner').first().html();
|
264 | footerData[that.columns[index].field] = footerCellHtml === ' ' ? null : footerCellHtml;
|
265 |
|
266 |
|
267 | footerHtml.push(footerCellHtml);
|
268 | });
|
269 |
|
270 | _this3.append(footerData);
|
271 |
|
272 | var $lastTableRow = _this3.$body.children().last();
|
273 |
|
274 | $.each($lastTableRow.children(), function (index, lastTableRowCell) {
|
275 | $(lastTableRowCell).html(footerHtml[index]);
|
276 | });
|
277 | }
|
278 |
|
279 | _this3.$el.tableExport($.extend({}, o.exportOptions, options));
|
280 |
|
281 | if (o.exportFooter) {
|
282 | _this3.load(data);
|
283 | }
|
284 | };
|
285 |
|
286 | var stateField = this.header.stateField;
|
287 | var isCardView = o.cardView;
|
288 |
|
289 | if (stateField) {
|
290 | this.hideColumn(stateField);
|
291 | }
|
292 | if (isCardView) {
|
293 | this.toggleView();
|
294 | }
|
295 | if (o.exportDataType === 'all' && o.pagination) {
|
296 | var eventName = o.sidePagination === 'server' ? 'post-body.bs.table' : 'page-change.bs.table';
|
297 | this.$el.one(eventName, function () {
|
298 | doExport();
|
299 | _this3.togglePagination();
|
300 | });
|
301 | this.togglePagination();
|
302 | } else if (o.exportDataType === 'selected') {
|
303 | var data = this.getData();
|
304 | var selectedData = this.getSelections();
|
305 | if (!selectedData.length) {
|
306 | return;
|
307 | }
|
308 |
|
309 | if (o.sidePagination === 'server') {
|
310 | data = _defineProperty({
|
311 | total: o.totalRows
|
312 | }, this.options.dataField, data);
|
313 | selectedData = _defineProperty({
|
314 | total: selectedData.length
|
315 | }, this.options.dataField, selectedData);
|
316 | }
|
317 |
|
318 | this.load(selectedData);
|
319 | doExport();
|
320 | this.load(data);
|
321 | } else {
|
322 | doExport();
|
323 | }
|
324 | if (stateField) {
|
325 | this.showColumn(stateField);
|
326 | }
|
327 | if (isCardView) {
|
328 | this.toggleView();
|
329 | }
|
330 | }
|
331 | }]);
|
332 |
|
333 | return _class;
|
334 | }($.BootstrapTable);
|
335 | })(jQuery);
|
336 | }); |
\ | No newline at end of file |