diff --git a/dist/js/tableexport.js b/dist/js/tableexport.js index ba14af0..b221889 100755 --- a/dist/js/tableexport.js +++ b/dist/js/tableexport.js @@ -26,15 +26,17 @@ bootstrapTheme = bootstrapSpacing = ""; } - return this.each(function () { + this.each(function () { var $el = $(this), - $rows = settings.headings ? $el.find('tr') : $el.find('tr:has(td)'), - thAdj = settings.headings ? 1 : 0, + $rows = $el.find('tbody').find('tr'), + $rows = settings.headings ? $rows.add($el.find('thead>tr')) : $rows, + $rows = settings.footers ? $rows.add($el.find('tfoor>tr')) : $rows, + thAdj = settings.headings ? $el.find('thead>tr').length : 0, fileName = settings.fileName === "id" ? ($el.attr('id') ? $el.attr('id') : $.fn.tableExport.defaultFileName) : settings.fileName, exporters = { xlsx: function (rDel, name) { var dataURL = $rows.map(function (i, val) { - if (!!~ignoreRows.indexOf(i-thAdj)) { return;} + if (!!~ignoreRows.indexOf(i-thAdj)) { return;} var $cols = $(val).find('th, td'); return [$cols.map(function (i, val) { if (!!~ignoreCols.indexOf(i)) { return;} @@ -50,7 +52,7 @@ })), myContent = $.fn.tableExport.xlsx.buttonContent, myClass = $.fn.tableExport.xlsx.defaultClass; - createObjButton(dataObject, name, myContent, myClass); + createObjButton(dataObject, myContent, myClass); }, xls: function (rdel, name) { var colD = $.fn.tableExport.xls.separator, @@ -71,7 +73,7 @@ })), myContent = $.fn.tableExport.xls.buttonContent, myClass = $.fn.tableExport.xls.defaultClass; - createObjButton(dataObject, name, myContent, myClass); + createObjButton(dataObject, myContent, myClass); }, csv: function (rdel, name) { var colD = $.fn.tableExport.csv.separator, @@ -92,7 +94,7 @@ })), myContent = $.fn.tableExport.csv.buttonContent, myClass = $.fn.tableExport.csv.defaultClass; - createObjButton(dataObject, name, myContent, myClass); + createObjButton(dataObject, myContent, myClass); }, txt: function (rdel, name) { var colD = $.fn.tableExport.txt.separator, @@ -113,7 +115,7 @@ })), myContent = $.fn.tableExport.txt.buttonContent, myClass = $.fn.tableExport.txt.defaultClass; - createObjButton(dataObject, name, myContent, myClass); + createObjButton(dataObject, myContent, myClass); } }; @@ -128,39 +130,32 @@ $caption.length ? $caption.append(exportButton) : $el.prepend('' + exportButton + ''); } - function createObjButton(dataObject, myFile, myContent, myClass) { - var exportButton = ""; + function createObjButton(dataObject, myContent, myClass) { + var exportButton = ""; checkCaption(exportButton); - addListener(myClass); - } - - function addListener(el) { - var $el = "." + el; - return $($el).on("click", function (e) { - if ($(this).data("obj")) { - e.preventDefault(); - var object = $(this).data("obj"), - data = object.data, - fileName = object.fileName, - mimeType = object.mimeType, - fileExtension = object.fileExtension; - export2file(data, mimeType, fileName, fileExtension); - } - }); } + }); + $("button[data-fileblob]").on("click", function () { + var object = $(this).data("fileblob"), + data = object.data, + fileName = object.fileName, + mimeType = object.mimeType, + fileExtension = object.fileExtension; + export2file(data, mimeType, fileName, fileExtension); }); }; // Define the plugin default properties. $.fn.tableExport.defaults = { - headings: true, // (Boolean), display table headings (th elements) in the first row, (default: true) + headings: true, // (Boolean), display table headings (th or td elements) in the , (default: true) + footers: false, // (Boolean), display table footers (th or td elements) in the , (default: false) formats: ["xls", "csv", "txt"], // (String[]), filetype(s) for the export, (default: ["xls", "csv", "txt"]) fileName: "id", // (id, String), filename for the downloaded file, (default: "id") bootstrap: true, // (Boolean), style buttons using bootstrap, (default: true) position: "bottom", // (top, bottom), position of the caption element relative to table, (default: "bottom") ignoreRows: null, // (Number, Number[]), row indices to exclude from the exported file (default: null) - ignoreCols: null // (Number, Number[]), column indices to exclude from the exported file (default: null) + ignoreCols: null // (Number, Number[]), column indices to exclude from the exported file (default: null) }; $.fn.tableExport.charset = "charset=utf-8"; diff --git a/dist/js/tableexport.min.js b/dist/js/tableexport.min.js index 784e464..9f14765 100755 --- a/dist/js/tableexport.min.js +++ b/dist/js/tableexport.min.js @@ -3,4 +3,4 @@ * Copyright 2015 Travis Clarke * Licensed under the MIT license */ -!function(t,e){function n(t){return String(t).replace(/[&<>'\/]/g,function(t){return l.fn.tableExport.entityMap[t]})}function o(t,e){e&&(t+=1462);var n=Date.parse(t);return(n-new Date(Date.UTC(1899,11,30)))/864e5}function a(t,e){for(var n={},a={s:{c:1e7,r:1e7},e:{c:0,r:0}},r=0;r!=t.length;++r)for(var i=0;i!=t[r].length;++i){a.s.r>r&&(a.s.r=r),a.s.c>i&&(a.s.c=i),a.e.r'+t+"")}function p(n,a,r,i){var f="";t(f),u(i)}function u(t){var e="."+t;return l(e).on("click",function(t){if(l(this).data("obj")){t.preventDefault();var e=l(this).data("obj"),n=e.data,o=e.fileName,a=e.mimeType,r=e.fileExtension;f(n,a,o,r)}})}var c=l(this),b=r.headings?c.find("tr"):c.find("tr:has(td)"),d=r.headings?1:0,E="id"===r.fileName?c.attr("id")?c.attr("id"):l.fn.tableExport.defaultFileName:r.fileName,m={xlsx:function(t,e){var o=b.map(function(t,e){if(!~s.indexOf(t-d)){var n=l(e).find("th, td");return[n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get()]}}).get(),a=n(JSON.stringify({data:o,fileName:e,mimeType:l.fn.tableExport.xlsx.mimeType,fileExtension:l.fn.tableExport.xlsx.fileExtension})),r=l.fn.tableExport.xlsx.buttonContent,i=l.fn.tableExport.xlsx.defaultClass;p(a,e,r,i)},xls:function(t,e){var o=l.fn.tableExport.xls.separator,a=b.map(function(t,e){if(!~s.indexOf(t-d)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get().join(o)}}).get().join(t),r=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.xls.mimeType,fileExtension:l.fn.tableExport.xls.fileExtension})),i=l.fn.tableExport.xls.buttonContent,f=l.fn.tableExport.xls.defaultClass;p(r,e,i,f)},csv:function(t,e){var o=l.fn.tableExport.csv.separator,a=b.map(function(t,e){if(!~s.indexOf(t-d)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get().join(o)}}).get().join(t),r=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.csv.mimeType,fileExtension:l.fn.tableExport.csv.fileExtension})),i=l.fn.tableExport.csv.buttonContent,f=l.fn.tableExport.csv.defaultClass;p(r,e,i,f)},txt:function(t,e){var o=l.fn.tableExport.txt.separator,a=b.map(function(t,e){if(!~s.indexOf(t-d)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get().join(o)}}).get().join(t),r=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.txt.mimeType,fileExtension:l.fn.tableExport.txt.fileExtension})),i=l.fn.tableExport.txt.buttonContent,f=l.fn.tableExport.txt.defaultClass;p(r,e,i,f)}};r.formats.forEach(function(t){m[t](i,E)})})},l.fn.tableExport.defaults={headings:!0,formats:["xls","csv","txt"],fileName:"id",bootstrap:!0,position:"bottom",ignoreRows:null,ignoreCols:null},l.fn.tableExport.charset="charset=utf-8",l.fn.tableExport.xlsx={defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},l.fn.tableExport.xls={defaultClass:"xls",buttonContent:"Export to xls",separator:" ",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},l.fn.tableExport.csv={defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"application/csv",fileExtension:".csv"},l.fn.tableExport.txt={defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"},l.fn.tableExport.defaultFileName="myDownload",l.fn.tableExport.defaultButton="button-default",l.fn.tableExport.bootstrap=["btn","btn-default","btn-toolbar"],l.fn.tableExport.rowDel="\r\n",l.fn.tableExport.entityMap={"&":"&","<":"<",">":">","'":"'","/":"/"}}(window); \ No newline at end of file +!function(t,e){function n(t){return String(t).replace(/[&<>'\/]/g,function(t){return l.fn.tableExport.entityMap[t]})}function o(t,e){e&&(t+=1462);var n=Date.parse(t);return(n-new Date(Date.UTC(1899,11,30)))/864e5}function a(t,e){for(var n={},a={s:{c:1e7,r:1e7},e:{c:0,r:0}},r=0;r!=t.length;++r)for(var i=0;i!=t[r].length;++i){a.s.r>r&&(a.s.r=r),a.s.c>i&&(a.s.c=i),a.e.r'+t+"")}function f(n,a,r){var i="";t(i)}var p=l(this),u=p.find("tbody").find("tr"),u=r.headings?u.add(p.find("thead>tr")):u,u=r.footers?u.add(p.find("tfoor>tr")):u,b=r.headings?p.find("thead>tr").length:0,d="id"===r.fileName?p.attr("id")?p.attr("id"):l.fn.tableExport.defaultFileName:r.fileName,c={xlsx:function(t,e){var o=u.map(function(t,e){if(!~s.indexOf(t-b)){var n=l(e).find("th, td");return[n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get()]}}).get(),a=n(JSON.stringify({data:o,fileName:e,mimeType:l.fn.tableExport.xlsx.mimeType,fileExtension:l.fn.tableExport.xlsx.fileExtension})),r=l.fn.tableExport.xlsx.buttonContent,i=l.fn.tableExport.xlsx.defaultClass;f(a,r,i)},xls:function(t,e){var o=l.fn.tableExport.xls.separator,a=u.map(function(t,e){if(!~s.indexOf(t-b)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get().join(o)}}).get().join(t),r=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.xls.mimeType,fileExtension:l.fn.tableExport.xls.fileExtension})),i=l.fn.tableExport.xls.buttonContent,p=l.fn.tableExport.xls.defaultClass;f(r,i,p)},csv:function(t,e){var o=l.fn.tableExport.csv.separator,a=u.map(function(t,e){if(!~s.indexOf(t-b)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get().join(o)}}).get().join(t),r=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.csv.mimeType,fileExtension:l.fn.tableExport.csv.fileExtension})),i=l.fn.tableExport.csv.buttonContent,p=l.fn.tableExport.csv.defaultClass;f(r,i,p)},txt:function(t,e){var o=l.fn.tableExport.txt.separator,a=u.map(function(t,e){if(!~s.indexOf(t-b)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get().join(o)}}).get().join(t),r=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.txt.mimeType,fileExtension:l.fn.tableExport.txt.fileExtension})),i=l.fn.tableExport.txt.buttonContent,p=l.fn.tableExport.txt.defaultClass;f(r,i,p)}};r.formats.forEach(function(t){c[t](i,d)})}),l("button[data-fileblob]").on("click",function(){var t=l(this).data("fileblob"),e=t.data,n=t.fileName,o=t.mimeType,a=t.fileExtension;f(e,o,n,a)})},l.fn.tableExport.defaults={headings:!0,footers:!1,formats:["xls","csv","txt"],fileName:"id",bootstrap:!0,position:"bottom",ignoreRows:null,ignoreCols:null},l.fn.tableExport.charset="charset=utf-8",l.fn.tableExport.xlsx={defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},l.fn.tableExport.xls={defaultClass:"xls",buttonContent:"Export to xls",separator:" ",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},l.fn.tableExport.csv={defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"application/csv",fileExtension:".csv"},l.fn.tableExport.txt={defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"},l.fn.tableExport.defaultFileName="myDownload",l.fn.tableExport.defaultButton="button-default",l.fn.tableExport.bootstrap=["btn","btn-default","btn-toolbar"],l.fn.tableExport.rowDel="\r\n",l.fn.tableExport.entityMap={"&":"&","<":"<",">":">","'":"'","/":"/"}}(window); \ No newline at end of file diff --git a/src/stable/js/tableexport.js b/src/stable/js/tableexport.js index ba14af0..b221889 100755 --- a/src/stable/js/tableexport.js +++ b/src/stable/js/tableexport.js @@ -26,15 +26,17 @@ bootstrapTheme = bootstrapSpacing = ""; } - return this.each(function () { + this.each(function () { var $el = $(this), - $rows = settings.headings ? $el.find('tr') : $el.find('tr:has(td)'), - thAdj = settings.headings ? 1 : 0, + $rows = $el.find('tbody').find('tr'), + $rows = settings.headings ? $rows.add($el.find('thead>tr')) : $rows, + $rows = settings.footers ? $rows.add($el.find('tfoor>tr')) : $rows, + thAdj = settings.headings ? $el.find('thead>tr').length : 0, fileName = settings.fileName === "id" ? ($el.attr('id') ? $el.attr('id') : $.fn.tableExport.defaultFileName) : settings.fileName, exporters = { xlsx: function (rDel, name) { var dataURL = $rows.map(function (i, val) { - if (!!~ignoreRows.indexOf(i-thAdj)) { return;} + if (!!~ignoreRows.indexOf(i-thAdj)) { return;} var $cols = $(val).find('th, td'); return [$cols.map(function (i, val) { if (!!~ignoreCols.indexOf(i)) { return;} @@ -50,7 +52,7 @@ })), myContent = $.fn.tableExport.xlsx.buttonContent, myClass = $.fn.tableExport.xlsx.defaultClass; - createObjButton(dataObject, name, myContent, myClass); + createObjButton(dataObject, myContent, myClass); }, xls: function (rdel, name) { var colD = $.fn.tableExport.xls.separator, @@ -71,7 +73,7 @@ })), myContent = $.fn.tableExport.xls.buttonContent, myClass = $.fn.tableExport.xls.defaultClass; - createObjButton(dataObject, name, myContent, myClass); + createObjButton(dataObject, myContent, myClass); }, csv: function (rdel, name) { var colD = $.fn.tableExport.csv.separator, @@ -92,7 +94,7 @@ })), myContent = $.fn.tableExport.csv.buttonContent, myClass = $.fn.tableExport.csv.defaultClass; - createObjButton(dataObject, name, myContent, myClass); + createObjButton(dataObject, myContent, myClass); }, txt: function (rdel, name) { var colD = $.fn.tableExport.txt.separator, @@ -113,7 +115,7 @@ })), myContent = $.fn.tableExport.txt.buttonContent, myClass = $.fn.tableExport.txt.defaultClass; - createObjButton(dataObject, name, myContent, myClass); + createObjButton(dataObject, myContent, myClass); } }; @@ -128,39 +130,32 @@ $caption.length ? $caption.append(exportButton) : $el.prepend('' + exportButton + ''); } - function createObjButton(dataObject, myFile, myContent, myClass) { - var exportButton = ""; + function createObjButton(dataObject, myContent, myClass) { + var exportButton = ""; checkCaption(exportButton); - addListener(myClass); - } - - function addListener(el) { - var $el = "." + el; - return $($el).on("click", function (e) { - if ($(this).data("obj")) { - e.preventDefault(); - var object = $(this).data("obj"), - data = object.data, - fileName = object.fileName, - mimeType = object.mimeType, - fileExtension = object.fileExtension; - export2file(data, mimeType, fileName, fileExtension); - } - }); } + }); + $("button[data-fileblob]").on("click", function () { + var object = $(this).data("fileblob"), + data = object.data, + fileName = object.fileName, + mimeType = object.mimeType, + fileExtension = object.fileExtension; + export2file(data, mimeType, fileName, fileExtension); }); }; // Define the plugin default properties. $.fn.tableExport.defaults = { - headings: true, // (Boolean), display table headings (th elements) in the first row, (default: true) + headings: true, // (Boolean), display table headings (th or td elements) in the , (default: true) + footers: false, // (Boolean), display table footers (th or td elements) in the , (default: false) formats: ["xls", "csv", "txt"], // (String[]), filetype(s) for the export, (default: ["xls", "csv", "txt"]) fileName: "id", // (id, String), filename for the downloaded file, (default: "id") bootstrap: true, // (Boolean), style buttons using bootstrap, (default: true) position: "bottom", // (top, bottom), position of the caption element relative to table, (default: "bottom") ignoreRows: null, // (Number, Number[]), row indices to exclude from the exported file (default: null) - ignoreCols: null // (Number, Number[]), column indices to exclude from the exported file (default: null) + ignoreCols: null // (Number, Number[]), column indices to exclude from the exported file (default: null) }; $.fn.tableExport.charset = "charset=utf-8"; diff --git a/src/stable/js/tableexport.min.js b/src/stable/js/tableexport.min.js index 784e464..9f14765 100755 --- a/src/stable/js/tableexport.min.js +++ b/src/stable/js/tableexport.min.js @@ -3,4 +3,4 @@ * Copyright 2015 Travis Clarke * Licensed under the MIT license */ -!function(t,e){function n(t){return String(t).replace(/[&<>'\/]/g,function(t){return l.fn.tableExport.entityMap[t]})}function o(t,e){e&&(t+=1462);var n=Date.parse(t);return(n-new Date(Date.UTC(1899,11,30)))/864e5}function a(t,e){for(var n={},a={s:{c:1e7,r:1e7},e:{c:0,r:0}},r=0;r!=t.length;++r)for(var i=0;i!=t[r].length;++i){a.s.r>r&&(a.s.r=r),a.s.c>i&&(a.s.c=i),a.e.r'+t+"")}function p(n,a,r,i){var f="";t(f),u(i)}function u(t){var e="."+t;return l(e).on("click",function(t){if(l(this).data("obj")){t.preventDefault();var e=l(this).data("obj"),n=e.data,o=e.fileName,a=e.mimeType,r=e.fileExtension;f(n,a,o,r)}})}var c=l(this),b=r.headings?c.find("tr"):c.find("tr:has(td)"),d=r.headings?1:0,E="id"===r.fileName?c.attr("id")?c.attr("id"):l.fn.tableExport.defaultFileName:r.fileName,m={xlsx:function(t,e){var o=b.map(function(t,e){if(!~s.indexOf(t-d)){var n=l(e).find("th, td");return[n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get()]}}).get(),a=n(JSON.stringify({data:o,fileName:e,mimeType:l.fn.tableExport.xlsx.mimeType,fileExtension:l.fn.tableExport.xlsx.fileExtension})),r=l.fn.tableExport.xlsx.buttonContent,i=l.fn.tableExport.xlsx.defaultClass;p(a,e,r,i)},xls:function(t,e){var o=l.fn.tableExport.xls.separator,a=b.map(function(t,e){if(!~s.indexOf(t-d)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get().join(o)}}).get().join(t),r=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.xls.mimeType,fileExtension:l.fn.tableExport.xls.fileExtension})),i=l.fn.tableExport.xls.buttonContent,f=l.fn.tableExport.xls.defaultClass;p(r,e,i,f)},csv:function(t,e){var o=l.fn.tableExport.csv.separator,a=b.map(function(t,e){if(!~s.indexOf(t-d)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get().join(o)}}).get().join(t),r=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.csv.mimeType,fileExtension:l.fn.tableExport.csv.fileExtension})),i=l.fn.tableExport.csv.buttonContent,f=l.fn.tableExport.csv.defaultClass;p(r,e,i,f)},txt:function(t,e){var o=l.fn.tableExport.txt.separator,a=b.map(function(t,e){if(!~s.indexOf(t-d)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get().join(o)}}).get().join(t),r=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.txt.mimeType,fileExtension:l.fn.tableExport.txt.fileExtension})),i=l.fn.tableExport.txt.buttonContent,f=l.fn.tableExport.txt.defaultClass;p(r,e,i,f)}};r.formats.forEach(function(t){m[t](i,E)})})},l.fn.tableExport.defaults={headings:!0,formats:["xls","csv","txt"],fileName:"id",bootstrap:!0,position:"bottom",ignoreRows:null,ignoreCols:null},l.fn.tableExport.charset="charset=utf-8",l.fn.tableExport.xlsx={defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},l.fn.tableExport.xls={defaultClass:"xls",buttonContent:"Export to xls",separator:" ",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},l.fn.tableExport.csv={defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"application/csv",fileExtension:".csv"},l.fn.tableExport.txt={defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"},l.fn.tableExport.defaultFileName="myDownload",l.fn.tableExport.defaultButton="button-default",l.fn.tableExport.bootstrap=["btn","btn-default","btn-toolbar"],l.fn.tableExport.rowDel="\r\n",l.fn.tableExport.entityMap={"&":"&","<":"<",">":">","'":"'","/":"/"}}(window); \ No newline at end of file +!function(t,e){function n(t){return String(t).replace(/[&<>'\/]/g,function(t){return l.fn.tableExport.entityMap[t]})}function o(t,e){e&&(t+=1462);var n=Date.parse(t);return(n-new Date(Date.UTC(1899,11,30)))/864e5}function a(t,e){for(var n={},a={s:{c:1e7,r:1e7},e:{c:0,r:0}},r=0;r!=t.length;++r)for(var i=0;i!=t[r].length;++i){a.s.r>r&&(a.s.r=r),a.s.c>i&&(a.s.c=i),a.e.r'+t+"")}function f(n,a,r){var i="";t(i)}var p=l(this),u=p.find("tbody").find("tr"),u=r.headings?u.add(p.find("thead>tr")):u,u=r.footers?u.add(p.find("tfoor>tr")):u,b=r.headings?p.find("thead>tr").length:0,d="id"===r.fileName?p.attr("id")?p.attr("id"):l.fn.tableExport.defaultFileName:r.fileName,c={xlsx:function(t,e){var o=u.map(function(t,e){if(!~s.indexOf(t-b)){var n=l(e).find("th, td");return[n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get()]}}).get(),a=n(JSON.stringify({data:o,fileName:e,mimeType:l.fn.tableExport.xlsx.mimeType,fileExtension:l.fn.tableExport.xlsx.fileExtension})),r=l.fn.tableExport.xlsx.buttonContent,i=l.fn.tableExport.xlsx.defaultClass;f(a,r,i)},xls:function(t,e){var o=l.fn.tableExport.xls.separator,a=u.map(function(t,e){if(!~s.indexOf(t-b)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get().join(o)}}).get().join(t),r=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.xls.mimeType,fileExtension:l.fn.tableExport.xls.fileExtension})),i=l.fn.tableExport.xls.buttonContent,p=l.fn.tableExport.xls.defaultClass;f(r,i,p)},csv:function(t,e){var o=l.fn.tableExport.csv.separator,a=u.map(function(t,e){if(!~s.indexOf(t-b)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get().join(o)}}).get().join(t),r=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.csv.mimeType,fileExtension:l.fn.tableExport.csv.fileExtension})),i=l.fn.tableExport.csv.buttonContent,p=l.fn.tableExport.csv.defaultClass;f(r,i,p)},txt:function(t,e){var o=l.fn.tableExport.txt.separator,a=u.map(function(t,e){if(!~s.indexOf(t-b)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get().join(o)}}).get().join(t),r=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.txt.mimeType,fileExtension:l.fn.tableExport.txt.fileExtension})),i=l.fn.tableExport.txt.buttonContent,p=l.fn.tableExport.txt.defaultClass;f(r,i,p)}};r.formats.forEach(function(t){c[t](i,d)})}),l("button[data-fileblob]").on("click",function(){var t=l(this).data("fileblob"),e=t.data,n=t.fileName,o=t.mimeType,a=t.fileExtension;f(e,o,n,a)})},l.fn.tableExport.defaults={headings:!0,footers:!1,formats:["xls","csv","txt"],fileName:"id",bootstrap:!0,position:"bottom",ignoreRows:null,ignoreCols:null},l.fn.tableExport.charset="charset=utf-8",l.fn.tableExport.xlsx={defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},l.fn.tableExport.xls={defaultClass:"xls",buttonContent:"Export to xls",separator:" ",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},l.fn.tableExport.csv={defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"application/csv",fileExtension:".csv"},l.fn.tableExport.txt={defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"},l.fn.tableExport.defaultFileName="myDownload",l.fn.tableExport.defaultButton="button-default",l.fn.tableExport.bootstrap=["btn","btn-default","btn-toolbar"],l.fn.tableExport.rowDel="\r\n",l.fn.tableExport.entityMap={"&":"&","<":"<",">":">","'":"'","/":"/"}}(window); \ No newline at end of file diff --git a/src/v3/tableexport-3.2.js b/src/v3/tableexport-3.2.js index ba14af0..b221889 100755 --- a/src/v3/tableexport-3.2.js +++ b/src/v3/tableexport-3.2.js @@ -26,15 +26,17 @@ bootstrapTheme = bootstrapSpacing = ""; } - return this.each(function () { + this.each(function () { var $el = $(this), - $rows = settings.headings ? $el.find('tr') : $el.find('tr:has(td)'), - thAdj = settings.headings ? 1 : 0, + $rows = $el.find('tbody').find('tr'), + $rows = settings.headings ? $rows.add($el.find('thead>tr')) : $rows, + $rows = settings.footers ? $rows.add($el.find('tfoor>tr')) : $rows, + thAdj = settings.headings ? $el.find('thead>tr').length : 0, fileName = settings.fileName === "id" ? ($el.attr('id') ? $el.attr('id') : $.fn.tableExport.defaultFileName) : settings.fileName, exporters = { xlsx: function (rDel, name) { var dataURL = $rows.map(function (i, val) { - if (!!~ignoreRows.indexOf(i-thAdj)) { return;} + if (!!~ignoreRows.indexOf(i-thAdj)) { return;} var $cols = $(val).find('th, td'); return [$cols.map(function (i, val) { if (!!~ignoreCols.indexOf(i)) { return;} @@ -50,7 +52,7 @@ })), myContent = $.fn.tableExport.xlsx.buttonContent, myClass = $.fn.tableExport.xlsx.defaultClass; - createObjButton(dataObject, name, myContent, myClass); + createObjButton(dataObject, myContent, myClass); }, xls: function (rdel, name) { var colD = $.fn.tableExport.xls.separator, @@ -71,7 +73,7 @@ })), myContent = $.fn.tableExport.xls.buttonContent, myClass = $.fn.tableExport.xls.defaultClass; - createObjButton(dataObject, name, myContent, myClass); + createObjButton(dataObject, myContent, myClass); }, csv: function (rdel, name) { var colD = $.fn.tableExport.csv.separator, @@ -92,7 +94,7 @@ })), myContent = $.fn.tableExport.csv.buttonContent, myClass = $.fn.tableExport.csv.defaultClass; - createObjButton(dataObject, name, myContent, myClass); + createObjButton(dataObject, myContent, myClass); }, txt: function (rdel, name) { var colD = $.fn.tableExport.txt.separator, @@ -113,7 +115,7 @@ })), myContent = $.fn.tableExport.txt.buttonContent, myClass = $.fn.tableExport.txt.defaultClass; - createObjButton(dataObject, name, myContent, myClass); + createObjButton(dataObject, myContent, myClass); } }; @@ -128,39 +130,32 @@ $caption.length ? $caption.append(exportButton) : $el.prepend('' + exportButton + ''); } - function createObjButton(dataObject, myFile, myContent, myClass) { - var exportButton = ""; + function createObjButton(dataObject, myContent, myClass) { + var exportButton = ""; checkCaption(exportButton); - addListener(myClass); - } - - function addListener(el) { - var $el = "." + el; - return $($el).on("click", function (e) { - if ($(this).data("obj")) { - e.preventDefault(); - var object = $(this).data("obj"), - data = object.data, - fileName = object.fileName, - mimeType = object.mimeType, - fileExtension = object.fileExtension; - export2file(data, mimeType, fileName, fileExtension); - } - }); } + }); + $("button[data-fileblob]").on("click", function () { + var object = $(this).data("fileblob"), + data = object.data, + fileName = object.fileName, + mimeType = object.mimeType, + fileExtension = object.fileExtension; + export2file(data, mimeType, fileName, fileExtension); }); }; // Define the plugin default properties. $.fn.tableExport.defaults = { - headings: true, // (Boolean), display table headings (th elements) in the first row, (default: true) + headings: true, // (Boolean), display table headings (th or td elements) in the , (default: true) + footers: false, // (Boolean), display table footers (th or td elements) in the , (default: false) formats: ["xls", "csv", "txt"], // (String[]), filetype(s) for the export, (default: ["xls", "csv", "txt"]) fileName: "id", // (id, String), filename for the downloaded file, (default: "id") bootstrap: true, // (Boolean), style buttons using bootstrap, (default: true) position: "bottom", // (top, bottom), position of the caption element relative to table, (default: "bottom") ignoreRows: null, // (Number, Number[]), row indices to exclude from the exported file (default: null) - ignoreCols: null // (Number, Number[]), column indices to exclude from the exported file (default: null) + ignoreCols: null // (Number, Number[]), column indices to exclude from the exported file (default: null) }; $.fn.tableExport.charset = "charset=utf-8"; diff --git a/src/v3/tableexport-3.2.min.js b/src/v3/tableexport-3.2.min.js index 784e464..9f14765 100755 --- a/src/v3/tableexport-3.2.min.js +++ b/src/v3/tableexport-3.2.min.js @@ -3,4 +3,4 @@ * Copyright 2015 Travis Clarke * Licensed under the MIT license */ -!function(t,e){function n(t){return String(t).replace(/[&<>'\/]/g,function(t){return l.fn.tableExport.entityMap[t]})}function o(t,e){e&&(t+=1462);var n=Date.parse(t);return(n-new Date(Date.UTC(1899,11,30)))/864e5}function a(t,e){for(var n={},a={s:{c:1e7,r:1e7},e:{c:0,r:0}},r=0;r!=t.length;++r)for(var i=0;i!=t[r].length;++i){a.s.r>r&&(a.s.r=r),a.s.c>i&&(a.s.c=i),a.e.r'+t+"")}function p(n,a,r,i){var f="";t(f),u(i)}function u(t){var e="."+t;return l(e).on("click",function(t){if(l(this).data("obj")){t.preventDefault();var e=l(this).data("obj"),n=e.data,o=e.fileName,a=e.mimeType,r=e.fileExtension;f(n,a,o,r)}})}var c=l(this),b=r.headings?c.find("tr"):c.find("tr:has(td)"),d=r.headings?1:0,E="id"===r.fileName?c.attr("id")?c.attr("id"):l.fn.tableExport.defaultFileName:r.fileName,m={xlsx:function(t,e){var o=b.map(function(t,e){if(!~s.indexOf(t-d)){var n=l(e).find("th, td");return[n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get()]}}).get(),a=n(JSON.stringify({data:o,fileName:e,mimeType:l.fn.tableExport.xlsx.mimeType,fileExtension:l.fn.tableExport.xlsx.fileExtension})),r=l.fn.tableExport.xlsx.buttonContent,i=l.fn.tableExport.xlsx.defaultClass;p(a,e,r,i)},xls:function(t,e){var o=l.fn.tableExport.xls.separator,a=b.map(function(t,e){if(!~s.indexOf(t-d)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get().join(o)}}).get().join(t),r=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.xls.mimeType,fileExtension:l.fn.tableExport.xls.fileExtension})),i=l.fn.tableExport.xls.buttonContent,f=l.fn.tableExport.xls.defaultClass;p(r,e,i,f)},csv:function(t,e){var o=l.fn.tableExport.csv.separator,a=b.map(function(t,e){if(!~s.indexOf(t-d)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get().join(o)}}).get().join(t),r=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.csv.mimeType,fileExtension:l.fn.tableExport.csv.fileExtension})),i=l.fn.tableExport.csv.buttonContent,f=l.fn.tableExport.csv.defaultClass;p(r,e,i,f)},txt:function(t,e){var o=l.fn.tableExport.txt.separator,a=b.map(function(t,e){if(!~s.indexOf(t-d)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get().join(o)}}).get().join(t),r=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.txt.mimeType,fileExtension:l.fn.tableExport.txt.fileExtension})),i=l.fn.tableExport.txt.buttonContent,f=l.fn.tableExport.txt.defaultClass;p(r,e,i,f)}};r.formats.forEach(function(t){m[t](i,E)})})},l.fn.tableExport.defaults={headings:!0,formats:["xls","csv","txt"],fileName:"id",bootstrap:!0,position:"bottom",ignoreRows:null,ignoreCols:null},l.fn.tableExport.charset="charset=utf-8",l.fn.tableExport.xlsx={defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},l.fn.tableExport.xls={defaultClass:"xls",buttonContent:"Export to xls",separator:" ",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},l.fn.tableExport.csv={defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"application/csv",fileExtension:".csv"},l.fn.tableExport.txt={defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"},l.fn.tableExport.defaultFileName="myDownload",l.fn.tableExport.defaultButton="button-default",l.fn.tableExport.bootstrap=["btn","btn-default","btn-toolbar"],l.fn.tableExport.rowDel="\r\n",l.fn.tableExport.entityMap={"&":"&","<":"<",">":">","'":"'","/":"/"}}(window); \ No newline at end of file +!function(t,e){function n(t){return String(t).replace(/[&<>'\/]/g,function(t){return l.fn.tableExport.entityMap[t]})}function o(t,e){e&&(t+=1462);var n=Date.parse(t);return(n-new Date(Date.UTC(1899,11,30)))/864e5}function a(t,e){for(var n={},a={s:{c:1e7,r:1e7},e:{c:0,r:0}},r=0;r!=t.length;++r)for(var i=0;i!=t[r].length;++i){a.s.r>r&&(a.s.r=r),a.s.c>i&&(a.s.c=i),a.e.r'+t+"")}function f(n,a,r){var i="";t(i)}var p=l(this),u=p.find("tbody").find("tr"),u=r.headings?u.add(p.find("thead>tr")):u,u=r.footers?u.add(p.find("tfoor>tr")):u,b=r.headings?p.find("thead>tr").length:0,d="id"===r.fileName?p.attr("id")?p.attr("id"):l.fn.tableExport.defaultFileName:r.fileName,c={xlsx:function(t,e){var o=u.map(function(t,e){if(!~s.indexOf(t-b)){var n=l(e).find("th, td");return[n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get()]}}).get(),a=n(JSON.stringify({data:o,fileName:e,mimeType:l.fn.tableExport.xlsx.mimeType,fileExtension:l.fn.tableExport.xlsx.fileExtension})),r=l.fn.tableExport.xlsx.buttonContent,i=l.fn.tableExport.xlsx.defaultClass;f(a,r,i)},xls:function(t,e){var o=l.fn.tableExport.xls.separator,a=u.map(function(t,e){if(!~s.indexOf(t-b)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get().join(o)}}).get().join(t),r=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.xls.mimeType,fileExtension:l.fn.tableExport.xls.fileExtension})),i=l.fn.tableExport.xls.buttonContent,p=l.fn.tableExport.xls.defaultClass;f(r,i,p)},csv:function(t,e){var o=l.fn.tableExport.csv.separator,a=u.map(function(t,e){if(!~s.indexOf(t-b)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get().join(o)}}).get().join(t),r=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.csv.mimeType,fileExtension:l.fn.tableExport.csv.fileExtension})),i=l.fn.tableExport.csv.buttonContent,p=l.fn.tableExport.csv.defaultClass;f(r,i,p)},txt:function(t,e){var o=l.fn.tableExport.txt.separator,a=u.map(function(t,e){if(!~s.indexOf(t-b)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get().join(o)}}).get().join(t),r=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.txt.mimeType,fileExtension:l.fn.tableExport.txt.fileExtension})),i=l.fn.tableExport.txt.buttonContent,p=l.fn.tableExport.txt.defaultClass;f(r,i,p)}};r.formats.forEach(function(t){c[t](i,d)})}),l("button[data-fileblob]").on("click",function(){var t=l(this).data("fileblob"),e=t.data,n=t.fileName,o=t.mimeType,a=t.fileExtension;f(e,o,n,a)})},l.fn.tableExport.defaults={headings:!0,footers:!1,formats:["xls","csv","txt"],fileName:"id",bootstrap:!0,position:"bottom",ignoreRows:null,ignoreCols:null},l.fn.tableExport.charset="charset=utf-8",l.fn.tableExport.xlsx={defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},l.fn.tableExport.xls={defaultClass:"xls",buttonContent:"Export to xls",separator:" ",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},l.fn.tableExport.csv={defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"application/csv",fileExtension:".csv"},l.fn.tableExport.txt={defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"},l.fn.tableExport.defaultFileName="myDownload",l.fn.tableExport.defaultButton="button-default",l.fn.tableExport.bootstrap=["btn","btn-default","btn-toolbar"],l.fn.tableExport.rowDel="\r\n",l.fn.tableExport.entityMap={"&":"&","<":"<",">":">","'":"'","/":"/"}}(window); \ No newline at end of file