From 6a418ecba9505b9e6720c187332ef69e2e009404 Mon Sep 17 00:00:00 2001 From: Diego Rabatone Oliveira Date: Sun, 9 Dec 2018 13:31:09 -0200 Subject: [PATCH] Add CSV Export renderer --- locales/pivot.pt.coffee | 3 +++ src/export_renderers.coffee | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/locales/pivot.pt.coffee b/locales/pivot.pt.coffee index 34d4596e..14ecddaa 100644 --- a/locales/pivot.pt.coffee +++ b/locales/pivot.pt.coffee @@ -34,6 +34,7 @@ callWithJQuery ($) -> cancel: "Cancelar", vs: "vs" by: "por" + csv_sep: ";" aggregators: "Contagem": tpl.count(frFmtInt) @@ -65,6 +66,8 @@ callWithJQuery ($) -> "Mapa de Calor": r["Heatmap"] "Mapa de Calor por Linhas": r["Row Heatmap"] "Mapa de Calor por Colunas": r["Col Heatmap"] + "TSV Export": r["Exportar para TSV"] + "CSV Export": r["Exportar para CSV"] if gcr $.pivotUtilities.locales.pt.gchart_renderers = diff --git a/src/export_renderers.coffee b/src/export_renderers.coffee index 6c781065..fa8a775e 100644 --- a/src/export_renderers.coffee +++ b/src/export_renderers.coffee @@ -9,11 +9,18 @@ callWithJQuery = (pivotModule) -> callWithJQuery ($) -> - $.pivotUtilities.export_renderers = "TSV Export": (pivotData, opts) -> - defaults = localeStrings: {} + svExporter = (pivotData, opts, separator) -> + defaults = localeStrings: { + csv_sep: "," + } opts = $.extend(true, {}, defaults, opts) + if separator == "tsv" + separator = "\t" + else + separator = opts.localeStrings.csv_sep + rowKeys = pivotData.getRowKeys() rowKeys.push [] if rowKeys.length == 0 colKeys = pivotData.getColKeys() @@ -48,9 +55,12 @@ callWithJQuery ($) -> result.push row text = "" for r in result - text += r.join("\t")+"\n" + text += r.join(separator)+"\n" return $("