diff --git a/dist/js/tableexport.js b/dist/js/tableexport.js index ee8d4ac..4764036 100644 --- a/dist/js/tableexport.js +++ b/dist/js/tableexport.js @@ -63,7 +63,7 @@ thAdj = self.settings.headings ? $el.find('thead>tr').length : 0, fileName = self.settings.fileName === "id" ? ($el.attr('id') ? $el.attr('id') : TableExport.prototype.defaultFileName) : self.settings.fileName, exporters = { - xlsx: function (rDel, name) { + xlsx: function (rDel, name, target) { var rcMap = {}, dataURL = $rows.map(function (ir, val) { if (!!~ignoreRows.indexOf(ir - thAdj) || $(val).is(ignoreCSS)) { @@ -98,9 +98,13 @@ break; } } - return new Array(total).concat($(val).text()); + return new Array(total).push({'val': $(val).text(), 'type': getTypeFromClass($(val))}); } +<<<<<<< HEAD return formatValue($(val).text()); +======= + return {'val': $(val).text(), 'type': getTypeFromClass($(val))}; +>>>>>>> eba4197235c01fe6fa9fcb1a714f1fb33d58395e }).get()]; }).get(), dataObject = TableExport.prototype.escapeHtml( @@ -112,9 +116,14 @@ })), myContent = TableExport.prototype.xlsx.buttonContent, myClass = TableExport.prototype.xlsx.defaultClass; - createObjButton(dataObject, myContent, myClass); + if (target) { + attachExportToButton(dataObject, target); + } + else { + createObjButton(dataObject, myContent, myClass); + } }, - xlsm: function (rDel, name) { + xlsm: function (rDel, name, target) { var rcMap = {}, dataURL = $rows.map(function (ir, val) { if (!!~ignoreRows.indexOf(ir - thAdj) || $(val).is(ignoreCSS)) { @@ -149,9 +158,13 @@ break; } } - return new Array(total).concat($(val).text()); + return new Array(total).push({'val': $(val).text(), 'type': getTypeFromClass($(val))}); } +<<<<<<< HEAD return formatValue($(val).text()); +======= + return {'val': $(val).text(), 'type': getTypeFromClass($(val))}; +>>>>>>> eba4197235c01fe6fa9fcb1a714f1fb33d58395e }).get()]; }).get(), dataObject = TableExport.prototype.escapeHtml( @@ -163,9 +176,14 @@ })), myContent = TableExport.prototype.xls.buttonContent, myClass = TableExport.prototype.xls.defaultClass; - createObjButton(dataObject, myContent, myClass); + if (target) { + attachExportToButton(dataObject, target); + } + else { + createObjButton(dataObject, myContent, myClass); + } }, - xls: function (rdel, name) { + xls: function (rdel, name, target) { var colD = TableExport.prototype.xls.separator, dataURL = $rows.map(function (i, val) { if (!!~ignoreRows.indexOf(i - thAdj) || $(val).is(ignoreCSS)) { @@ -179,7 +197,11 @@ if ($(val).is(emptyCSS)) { return " " } +<<<<<<< HEAD return formatValue($(val).text()); +======= + return {'val': $(val).text(), 'type': getTypeFromClass($(val))}; +>>>>>>> eba4197235c01fe6fa9fcb1a714f1fb33d58395e }).get().join(colD); }).get().join(rdel), dataObject = TableExport.prototype.escapeHtml( @@ -191,9 +213,14 @@ })), myContent = TableExport.prototype.xls.buttonContent, myClass = TableExport.prototype.xls.defaultClass; - createObjButton(dataObject, myContent, myClass); + if (target) { + attachExportToButton(dataObject, target); + } + else { + createObjButton(dataObject, myContent, myClass); + } }, - csv: function (rdel, name) { + csv: function (rdel, name, target) { var colD = TableExport.prototype.csv.separator, dataURL = $rows.map(function (i, val) { if (!!~ignoreRows.indexOf(i - thAdj) || $(val).is(ignoreCSS)) { @@ -219,9 +246,14 @@ })), myContent = TableExport.prototype.csv.buttonContent, myClass = TableExport.prototype.csv.defaultClass; - createObjButton(dataObject, myContent, myClass); + if (target) { + attachExportToButton(dataObject, target); + } + else { + createObjButton(dataObject, myContent, myClass); + } }, - txt: function (rdel, name) { + txt: function (rdel, name, target) { var colD = TableExport.prototype.txt.separator, dataURL = $rows.map(function (i, val) { if (!!~ignoreRows.indexOf(i - thAdj) || $(val).is(ignoreCSS)) { @@ -247,7 +279,12 @@ })), myContent = TableExport.prototype.txt.buttonContent, myClass = TableExport.prototype.txt.defaultClass; - createObjButton(dataObject, myContent, myClass); + if (target) { + attachExportToButton(dataObject, target); + } + else { + createObjButton(dataObject, myContent, myClass); + } } }; @@ -255,10 +292,15 @@ function (key) { XLSX && key === 'xls' ? key = 'xlsm' : false; !XLSX && key === 'xlsx' ? key = null : false; - key && exporters[key](rowD, fileName); + var target; + if (self.settings['targets']) { + key in self.settings['targets'] ? target = self.settings['targets'][key] : null; + } + key && exporters[key](rowD, fileName, target); } ); +<<<<<<< HEAD /** * Removes leading/trailing whitespace from cell string * @param string {String} @@ -272,6 +314,25 @@ * Initializes table caption with export buttons * @param exportButton {HTMLButtonElement} */ +======= + function getTypeFromClass(cell) { + if (cell.hasClass('te-string')) { + return 's'; + } else if (cell.hasClass('te-number')) { + return 'n'; + } else if (cell.hasClass('te-boolean')) { + return 'b'; + } else { + return ''; + } + } + + function unescapeHtml(string) { + var doc = new DOMParser().parseFromString(string, "text/html"); + return doc.documentElement.textContent; + } + +>>>>>>> eba4197235c01fe6fa9fcb1a714f1fb33d58395e function checkCaption(exportButton) { var $caption = $el.find('caption:not(.head)'); $caption.length ? $caption.append(exportButton) : $el.prepend('