* extensions: https://github.com/hhurz/tableExport.jquery.plugin
*/
var Utils = $__default["default"].fn.bootstrapTable.utils;
var TYPE_NAME = {
json: 'JSON',
xml: 'XML',
png: 'PNG',
csv: 'CSV',
txt: 'TXT',
sql: 'SQL',
doc: 'MS-Word',
excel: 'MS-Excel',
xlsx: 'MS-Excel (OpenXML)',
powerpoint: 'MS-Powerpoint',
pdf: 'PDF'
};
$__default["default"].extend($__default["default"].fn.bootstrapTable.defaults, {
showExport: false,
exportDataType: 'basic',
// basic, all, selected
exportTypes: ['json', 'xml', 'csv', 'txt', 'sql', 'excel'],
exportOptions: {
onCellHtmlData: function onCellHtmlData(cell, rowIndex, colIndex, htmlData) {
if (cell.is('th')) {
return cell.find('.th-inner').text();
}
return htmlData;
}
},
exportFooter: false
});
$__default["default"].extend($__default["default"].fn.bootstrapTable.columnDefaults, {
forceExport: false,
forceHide: false
});
$__default["default"].extend($__default["default"].fn.bootstrapTable.defaults.icons, {
export: {
bootstrap3: 'glyphicon-export icon-share',
bootstrap5: 'bi-download',
materialize: 'file_download',
'bootstrap-table': 'icon-download'
}[$__default["default"].fn.bootstrapTable.theme] || 'fa-download'
});
$__default["default"].extend($__default["default"].fn.bootstrapTable.locales, {
formatExport: function formatExport() {
return 'Export data';
}
});
$__default["default"].extend($__default["default"].fn.bootstrapTable.defaults, $__default["default"].fn.bootstrapTable.locales);
$__default["default"].fn.bootstrapTable.methods.push('exportTable');
$__default["default"].extend($__default["default"].fn.bootstrapTable.defaults, {
// eslint-disable-next-line no-unused-vars
onExportSaved: function onExportSaved(exportedRows) {
return false;
}
});
$__default["default"].extend($__default["default"].fn.bootstrapTable.Constructor.EVENTS, {
'export-saved.bs.table': 'onExportSaved'
});
$__default["default"].BootstrapTable = /*#__PURE__*/function (_$$BootstrapTable) {
_inherits(_class, _$$BootstrapTable);
var _super = _createSuper(_class);
function _class() {
_classCallCheck(this, _class);
return _super.apply(this, arguments);
}
_createClass(_class, [{
key: "initToolbar",
value: function initToolbar() {
var _this = this,
_get2;
var o = this.options;
var exportTypes = o.exportTypes;
this.showToolbar = this.showToolbar || o.showExport;
if (this.options.showExport) {
if (typeof exportTypes === 'string') {
var types = exportTypes.slice(1, -1).replace(/ /g, '').split(',');
exportTypes = types.map(function (t) {
return t.slice(1, -1);
});
}
this.$export = this.$toolbar.find('>.columns div.export');
if (this.$export.length) {
this.updateExportButton();
return;
}
this.buttons = Object.assign(this.buttons, {
export: {
html: function html() {
if (exportTypes.length === 1) {
return "\n \n \n
\n ");
}
var html = [];
html.push("\n \n \n ").concat(_this.constants.html.toolbarDropdown[0], "\n "));
var _iterator = _createForOfIteratorHelper(exportTypes),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var type = _step.value;
if (TYPE_NAME.hasOwnProperty(type)) {
var $item = $__default["default"](Utils.sprintf(_this.constants.html.pageDropdownItem, '', TYPE_NAME[type]));
$item.attr('data-type', type);
html.push($item.prop('outerHTML'));
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
html.push(_this.constants.html.toolbarDropdown[1], '
');
return html.join('');
}
}
});
}
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
(_get2 = _get(_getPrototypeOf(_class.prototype), "initToolbar", this)).call.apply(_get2, [this].concat(args));
this.$export = this.$toolbar.find('>.columns div.export');
if (!this.options.showExport) {
return;
}
this.updateExportButton();
var $exportButtons = this.$export.find('[data-type]');
if (exportTypes.length === 1) {
$exportButtons = this.$export;
}
$exportButtons.click(function (e) {
e.preventDefault();
var type = $__default["default"](e.currentTarget).data('type');
var exportOptions = {
type: type,
escape: false
};
_this.exportTable(exportOptions);
});
this.handleToolbar();
}
}, {
key: "handleToolbar",
value: function handleToolbar() {
if (!this.$export) {
return;
}
if (_get(_getPrototypeOf(_class.prototype), "handleToolbar", this)) {
_get(_getPrototypeOf(_class.prototype), "handleToolbar", this).call(this);
}
}
}, {
key: "exportTable",
value: function exportTable(options) {
var _this2 = this;
var o = this.options;
var stateField = this.header.stateField;
var isCardView = o.cardView;
var doExport = function doExport(callback) {
if (stateField) {
_this2.hideColumn(stateField);
}
if (isCardView) {
_this2.toggleView();
}
_this2.columns.forEach(function (row) {
if (row.forceHide) {
_this2.hideColumn(row.field);
}
});
var data = _this2.getData();
if (o.detailView && o.detailViewIcon) {
var detailViewIndex = o.detailViewAlign === 'left' ? 0 : _this2.getVisibleFields().length + Utils.getDetailViewIndexOffset(_this2.options);
o.exportOptions.ignoreColumn = [detailViewIndex].concat(o.exportOptions.ignoreColumn || []);
}
if (o.exportFooter) {
var $footerRow = _this2.$tableFooter.find('tr').first();
var footerData = {};
var footerHtml = [];
$__default["default"].each($footerRow.children(), function (index, footerCell) {
var footerCellHtml = $__default["default"](footerCell).children('.th-inner').first().html();
footerData[_this2.columns[index].field] = footerCellHtml === ' ' ? null : footerCellHtml; // grab footer cell text into cell index-based array
footerHtml.push(footerCellHtml);
});
_this2.$body.append(_this2.$body.children().last()[0].outerHTML);
var $lastTableRow = _this2.$body.children().last();
$__default["default"].each($lastTableRow.children(), function (index, lastTableRowCell) {
$__default["default"](lastTableRowCell).html(footerHtml[index]);
});
}
var hiddenColumns = _this2.getHiddenColumns();
hiddenColumns.forEach(function (row) {
if (row.forceExport) {
_this2.showColumn(row.field);
}
});
if (typeof o.exportOptions.fileName === 'function') {
options.fileName = o.exportOptions.fileName();
}
_this2.$el.tableExport($__default["default"].extend({
onAfterSaveToFile: function onAfterSaveToFile() {
if (o.exportFooter) {
_this2.load(data);
}
if (stateField) {
_this2.showColumn(stateField);
}
if (isCardView) {
_this2.toggleView();
}
hiddenColumns.forEach(function (row) {
if (row.forceExport) {
_this2.hideColumn(row.field);
}
});
_this2.columns.forEach(function (row) {
if (row.forceHide) {
_this2.showColumn(row.field);
}
});
if (callback) callback();
}
}, o.exportOptions, options));
};
if (o.exportDataType === 'all' && o.pagination) {
var eventName = o.sidePagination === 'server' ? 'post-body.bs.table' : 'page-change.bs.table';
var virtualScroll = this.options.virtualScroll;
this.$el.one(eventName, function () {
setTimeout(function () {
doExport(function () {
_this2.options.virtualScroll = virtualScroll;
_this2.togglePagination();
});
}, 0);
});
this.options.virtualScroll = false;
this.togglePagination();
this.trigger('export-saved', this.getData());
} else if (o.exportDataType === 'selected') {
var data = this.getData();
var selectedData = this.getSelections();
var pagination = o.pagination;
if (!selectedData.length) {
return;
}
if (o.sidePagination === 'server') {
data = _defineProperty({
total: o.totalRows
}, this.options.dataField, data);
selectedData = _defineProperty({
total: selectedData.length
}, this.options.dataField, selectedData);
}
this.load(selectedData);
if (pagination) {
this.togglePagination();
}
doExport(function () {
if (pagination) {
_this2.togglePagination();
}
_this2.load(data);
});
this.trigger('export-saved', selectedData);
} else {
doExport();
this.trigger('export-saved', this.getData(true));
}
}
}, {
key: "updateSelected",
value: function updateSelected() {
_get(_getPrototypeOf(_class.prototype), "updateSelected", this).call(this);
this.updateExportButton();
}
}, {
key: "updateExportButton",
value: function updateExportButton() {
if (this.options.exportDataType === 'selected') {
this.$export.find('> button').prop('disabled', !this.getSelections().length);
}
}
}]);
return _class;
}($__default["default"].BootstrapTable);
}));