From 7404174c2b39ccd1e5f262f881c3e78aa77e7148 Mon Sep 17 00:00:00 2001 From: Vladislav Lyshenko Date: Wed, 16 Dec 2015 16:40:18 +0200 Subject: [PATCH] Fix double quote replace in csv export --- assets/js/kv-grid-export.js | 2 +- assets/js/kv-grid-export.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/js/kv-grid-export.js b/assets/js/kv-grid-export.js index ef16f2f5..6bd2d1a4 100644 --- a/assets/js/kv-grid-export.js +++ b/assets/js/kv-grid-export.js @@ -324,7 +324,7 @@ var $row = $(row), $cols = $row.find(self.columns); return $cols.map(function (j, col) { var $col = $(col), text = $col.text().trim(); - return text.replace('"', '""'); // escape double quotes + return text.replace(/"/g, '""'); // escape double quotes }).get().join(tmpColDelim); }).get().join(tmpRowDelim) .split(tmpRowDelim).join(rowD) diff --git a/assets/js/kv-grid-export.min.js b/assets/js/kv-grid-export.min.js index a5c1577e..4a216e56 100644 --- a/assets/js/kv-grid-export.min.js +++ b/assets/js/kv-grid-export.min.js @@ -11,4 +11,4 @@ * Copyright: 2015, Kartik Visweswaran, Krajee.com * For more JQuery plugins visit http://plugins.krajee.com * For more Yii related demos visit http://demos.krajee.com - */!function(e){"use strict";var t=function(e,t,o){return e.split(t).join(o)},o=function(t,o){return null===t||void 0===t||0===t.length||o&&""===e.trim(t)},n=function(e,t,o,n){var i=screen.width/2-o/2,r=60,s=window.open("",t,"",!0);return s.close(),window.open(e,t,"toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width="+o+", height="+n+", top="+r+", left="+i)},i=function(e){return e.toLowerCase().replace(/[^\w ]+/g,"").replace(/ +/g,"-")},r={html:'{css}{data}',pdf:"{before}\n{data}\n{after}",excel:'{css}{data}',popup:'Grid Export - © Krajee{msg}'},s=function(t,o){this.$element=e(t);var n=o.gridOpts,i=o.genOpts;this.$grid=e("#"+n.gridId),this.messages=n.messages,this.target=n.target,this.exportConversions=n.exportConversions,this.showConfirmAlert=n.showConfirmAlert,this.filename=i.filename,this.showHeader=i.showHeader,this.showFooter=i.showFooter,this.showPageSummary=i.showPageSummary,this.$table=this.$grid.find(".kv-grid-table:first"),this.$form=this.$grid.find("form.kv-export-form"),this.encoding=this.$form.find('[name="export_encoding"]').val(),this.columns=this.showHeader?"td,th":"td",this.alertMsg=o.alertMsg,this.config=o.config,this.popup="",this.listen()};s.prototype={constructor:s,getArray:function(t){var n=this,r=n.clean(t),s=[],a={};return void 0!==n.config.colHeads&&n.config.colHeads.length>0?s=n.config.colHeads:r.find("thead tr th").each(function(t){var r=e(this).text().trim(),a=i(r);s[t]=!n.config.slugColHeads||o(a)?"col_"+t:a}),r.find('tbody tr:has("td")').each(function(t){a[t]={},e(this).children("td").each(function(o){var n=s[o];a[t][n]=e(this).text().trim()})}),a},notify:function(e){var t=this;if(!t.showConfirmAlert)return e.preventDefault(),!0;var n=t.messages,i=o(t.alertMsg)?"":t.alertMsg,r=o(n.allowPopups)?"":n.allowPopups,s=o(n.confirmDownload)?"":n.confirmDownload,a="";return a=i.length&&r.length?i+"\n\n"+r:!i.length&&r.length?r:i.length&&!r.length?i:"",s.length&&(a=a+"\n\n"+s),e.preventDefault(),o(a)?!0:t.kvConfirm(a)},kvConfirm:function(e){try{return window.confirm(e)}catch(t){return!0}},setPopupAlert:function(e){var t=this;if(void 0!==t.popup.document)if(arguments.length&&arguments[1]){var o=t.popup.document.getElementsByTagName("body");setTimeout(function(){o[0].innerHTML=e},4e3)}else{var n=r.popup.replace("{msg}",e);t.popup.document.write(n)}},listenClick:function(e){var t=this,n=arguments.length>1?arguments[1]:"";t.$element.on("click",function(i){t.notify(i)&&(o(n)?t[e]():t[e](n),i.preventDefault())})},listen:function(){var e=this;"_popup"===e.target&&e.$form.on("submit",function(){setTimeout(function(){e.setPopupAlert(e.messages.downloadComplete,!0)},1e3)}),e.$element.hasClass("export-csv")&&e.listenClick("exportTEXT","csv"),e.$element.hasClass("export-txt")&&e.listenClick("exportTEXT","txt"),e.$element.hasClass("export-html")&&e.listenClick("exportHTML"),e.$element.hasClass("export-xls")&&e.listenClick("exportEXCEL"),e.$element.hasClass("export-json")&&e.listenClick("exportJSON"),e.$element.hasClass("export-pdf")&&e.listenClick("exportPDF")},clean:function(t){var o=this,n=o.$table.clone();n.find("tr.filters").remove(),n.find("th").removeAttr("rowspan"),n.find("th").find("a").each(function(){e(this).contents().unwrap()}),n.find("input").remove(),o.showHeader||n.find("thead").remove(),o.showPageSummary||n.find("tfoot.kv-page-summary").remove(),o.showFooter||n.find("tfoot.kv-table-footer").remove(),o.showCaption||n.find("kv-table-caption").remove(),n.find(".skip-export").remove(),n.find(".skip-export-"+t).remove();var i=n.html();return i=o.preProcess(i),n.html(i),n},preProcess:function(e){var o,n=this,i=n.exportConversions,r=i.length,s=e;if(r>0)for(var a=0;r>a;a++)o=i[a],s=t(s,o.from,o.to);return s},download:function(e,t){var i=this,r=i.$element.data("format"),s=o(i.config)?{}:i.config;i.$form.find('[name="export_filetype"]').val(e),i.$form.find('[name="export_filename"]').val(i.filename),i.$form.find('[name="export_content"]').val(t),i.$form.find('[name="export_mime"]').val(r),i.$form.find('[name="export_config"]').val("pdf"===e?JSON.stringify(s):""),"_popup"===i.target&&(i.popup=n("","kvDownloadDialog",350,120),i.popup.focus(),i.setPopupAlert(i.messages.downloadProgress)),i.$form.submit()},exportHTML:function(){var t=this,o=t.clean("html"),n=t.config,i=t.config.cssFile&&n.cssFile.length?'':"",s=r.html.replace("{encoding}",t.encoding).replace("{css}",i).replace("{data}",e("
").html(o).html());t.download("html",s)},exportPDF:function(){var t=this,n=t.clean("pdf"),i=o(t.config.contentBefore)?"":t.config.contentBefore,s=o(t.config.contentAfter)?"":t.config.contentAfter,a=t.config.css,l=r.pdf.replace("{css}",a).replace("{before}",i).replace("{after}",s).replace("{data}",e("
").html(n).html());t.download("pdf",l)},exportTEXT:function(t){var o=this,n=o.clean(t),i=n.find("tr:has("+o.columns+")"),r=String.fromCharCode(11),s=String.fromCharCode(0),a='"'+o.config.colDelimiter+'"',l='"'+o.config.rowDelimiter+'"',c='"'+i.map(function(t,n){var i=e(n),s=i.find(o.columns);return s.map(function(t,o){var n=e(o),i=n.text().trim();return i.replace('"','""')}).get().join(r)}).get().join(s).split(s).join(l).split(r).join(a)+'"';o.download(t,c)},exportJSON:function(){var e=this,t=e.getArray("json");t=JSON.stringify(t,e.config.jsonReplacer,e.config.indentSpace),e.download("json",t)},exportEXCEL:function(){var t,o,n=this,i=n.clean("xls"),s=n.config,a=s.cssFile&&n.config.cssFile.length?'':"";i.find("td[data-raw-value]").each(function(){o=e(this),(o.css("mso-number-format")||0===o.css("mso-number-format")||"0"===o.css("mso-number-format"))&&o.html(o.attr("data-raw-value")).removeAttr("data-raw-value")}),t=r.excel.replace("{encoding}",n.encoding).replace("{css}",a).replace("{worksheet}",n.config.worksheet).replace("{data}",e("
").html(i).html()).replace(/"/g,"'"),n.download("xls",t)}},e.fn.gridexport=function(t){var o=Array.apply(null,arguments);return o.shift(),this.each(function(){var n=e(this),i=n.data("gridexport"),r="object"==typeof t&&t;i||n.data("gridexport",i=new s(this,e.extend({},e.fn.gridexport.defaults,r,e(this).data()))),"string"==typeof t&&i[t].apply(i,o)})},e.fn.gridexport.defaults={},e.fn.gridexport.Constructor=s}(window.jQuery); \ No newline at end of file + */!function(e){"use strict";var t=function(e,t,o){return e.split(t).join(o)},o=function(t,o){return null===t||void 0===t||0===t.length||o&&""===e.trim(t)},n=function(e,t,o,n){var i=screen.width/2-o/2,r=60,s=window.open("",t,"",!0);return s.close(),window.open(e,t,"toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width="+o+", height="+n+", top="+r+", left="+i)},i=function(e){return e.toLowerCase().replace(/[^\w ]+/g,"").replace(/ +/g,"-")},r={html:'{css}{data}',pdf:"{before}\n{data}\n{after}",excel:'{css}{data}',popup:'Grid Export - © Krajee{msg}'},s=function(t,o){this.$element=e(t);var n=o.gridOpts,i=o.genOpts;this.$grid=e("#"+n.gridId),this.messages=n.messages,this.target=n.target,this.exportConversions=n.exportConversions,this.showConfirmAlert=n.showConfirmAlert,this.filename=i.filename,this.showHeader=i.showHeader,this.showFooter=i.showFooter,this.showPageSummary=i.showPageSummary,this.$table=this.$grid.find(".kv-grid-table:first"),this.$form=this.$grid.find("form.kv-export-form"),this.encoding=this.$form.find('[name="export_encoding"]').val(),this.columns=this.showHeader?"td,th":"td",this.alertMsg=o.alertMsg,this.config=o.config,this.popup="",this.listen()};s.prototype={constructor:s,getArray:function(t){var n=this,r=n.clean(t),s=[],a={};return void 0!==n.config.colHeads&&n.config.colHeads.length>0?s=n.config.colHeads:r.find("thead tr th").each(function(t){var r=e(this).text().trim(),a=i(r);s[t]=!n.config.slugColHeads||o(a)?"col_"+t:a}),r.find('tbody tr:has("td")').each(function(t){a[t]={},e(this).children("td").each(function(o){var n=s[o];a[t][n]=e(this).text().trim()})}),a},notify:function(e){var t=this;if(!t.showConfirmAlert)return e.preventDefault(),!0;var n=t.messages,i=o(t.alertMsg)?"":t.alertMsg,r=o(n.allowPopups)?"":n.allowPopups,s=o(n.confirmDownload)?"":n.confirmDownload,a="";return a=i.length&&r.length?i+"\n\n"+r:!i.length&&r.length?r:i.length&&!r.length?i:"",s.length&&(a=a+"\n\n"+s),e.preventDefault(),o(a)?!0:t.kvConfirm(a)},kvConfirm:function(e){try{return window.confirm(e)}catch(t){return!0}},setPopupAlert:function(e){var t=this;if(void 0!==t.popup.document)if(arguments.length&&arguments[1]){var o=t.popup.document.getElementsByTagName("body");setTimeout(function(){o[0].innerHTML=e},4e3)}else{var n=r.popup.replace("{msg}",e);t.popup.document.write(n)}},listenClick:function(e){var t=this,n=arguments.length>1?arguments[1]:"";t.$element.on("click",function(i){t.notify(i)&&(o(n)?t[e]():t[e](n),i.preventDefault())})},listen:function(){var e=this;"_popup"===e.target&&e.$form.on("submit",function(){setTimeout(function(){e.setPopupAlert(e.messages.downloadComplete,!0)},1e3)}),e.$element.hasClass("export-csv")&&e.listenClick("exportTEXT","csv"),e.$element.hasClass("export-txt")&&e.listenClick("exportTEXT","txt"),e.$element.hasClass("export-html")&&e.listenClick("exportHTML"),e.$element.hasClass("export-xls")&&e.listenClick("exportEXCEL"),e.$element.hasClass("export-json")&&e.listenClick("exportJSON"),e.$element.hasClass("export-pdf")&&e.listenClick("exportPDF")},clean:function(t){var o=this,n=o.$table.clone();n.find("tr.filters").remove(),n.find("th").removeAttr("rowspan"),n.find("th").find("a").each(function(){e(this).contents().unwrap()}),n.find("input").remove(),o.showHeader||n.find("thead").remove(),o.showPageSummary||n.find("tfoot.kv-page-summary").remove(),o.showFooter||n.find("tfoot.kv-table-footer").remove(),o.showCaption||n.find("kv-table-caption").remove(),n.find(".skip-export").remove(),n.find(".skip-export-"+t).remove();var i=n.html();return i=o.preProcess(i),n.html(i),n},preProcess:function(e){var o,n=this,i=n.exportConversions,r=i.length,s=e;if(r>0)for(var a=0;r>a;a++)o=i[a],s=t(s,o.from,o.to);return s},download:function(e,t){var i=this,r=i.$element.data("format"),s=o(i.config)?{}:i.config;i.$form.find('[name="export_filetype"]').val(e),i.$form.find('[name="export_filename"]').val(i.filename),i.$form.find('[name="export_content"]').val(t),i.$form.find('[name="export_mime"]').val(r),i.$form.find('[name="export_config"]').val("pdf"===e?JSON.stringify(s):""),"_popup"===i.target&&(i.popup=n("","kvDownloadDialog",350,120),i.popup.focus(),i.setPopupAlert(i.messages.downloadProgress)),i.$form.submit()},exportHTML:function(){var t=this,o=t.clean("html"),n=t.config,i=t.config.cssFile&&n.cssFile.length?'':"",s=r.html.replace("{encoding}",t.encoding).replace("{css}",i).replace("{data}",e("
").html(o).html());t.download("html",s)},exportPDF:function(){var t=this,n=t.clean("pdf"),i=o(t.config.contentBefore)?"":t.config.contentBefore,s=o(t.config.contentAfter)?"":t.config.contentAfter,a=t.config.css,l=r.pdf.replace("{css}",a).replace("{before}",i).replace("{after}",s).replace("{data}",e("
").html(n).html());t.download("pdf",l)},exportTEXT:function(t){var o=this,n=o.clean(t),i=n.find("tr:has("+o.columns+")"),r=String.fromCharCode(11),s=String.fromCharCode(0),a='"'+o.config.colDelimiter+'"',l='"'+o.config.rowDelimiter+'"',c='"'+i.map(function(t,n){var i=e(n),s=i.find(o.columns);return s.map(function(t,o){var n=e(o),i=n.text().trim();return i.replace(/"/g,'""')}).get().join(r)}).get().join(s).split(s).join(l).split(r).join(a)+'"';o.download(t,c)},exportJSON:function(){var e=this,t=e.getArray("json");t=JSON.stringify(t,e.config.jsonReplacer,e.config.indentSpace),e.download("json",t)},exportEXCEL:function(){var t,o,n=this,i=n.clean("xls"),s=n.config,a=s.cssFile&&n.config.cssFile.length?'':"";i.find("td[data-raw-value]").each(function(){o=e(this),(o.css("mso-number-format")||0===o.css("mso-number-format")||"0"===o.css("mso-number-format"))&&o.html(o.attr("data-raw-value")).removeAttr("data-raw-value")}),t=r.excel.replace("{encoding}",n.encoding).replace("{css}",a).replace("{worksheet}",n.config.worksheet).replace("{data}",e("
").html(i).html()).replace(/"/g,"'"),n.download("xls",t)}},e.fn.gridexport=function(t){var o=Array.apply(null,arguments);return o.shift(),this.each(function(){var n=e(this),i=n.data("gridexport"),r="object"==typeof t&&t;i||n.data("gridexport",i=new s(this,e.extend({},e.fn.gridexport.defaults,r,e(this).data()))),"string"==typeof t&&i[t].apply(i,o)})},e.fn.gridexport.defaults={},e.fn.gridexport.Constructor=s}(window.jQuery); \ No newline at end of file