Skip to content

Commit

Permalink
Add CSV Export renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
diraol committed Dec 9, 2018
1 parent a9cabee commit f6451af
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions locales/pivot.pt.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ callWithJQuery ($) ->
cancel: "Cancelar",
vs: "vs"
by: "por"
csv_sep: ";"

aggregators:
"Contagem": tpl.count(frFmtInt)
Expand Down Expand Up @@ -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"]
"Exportar para TSV": r["TSV Export"]
"Exportar para CSV": r["CSV Export"]

if gcr
$.pivotUtilities.locales.pt.gchart_renderers =
Expand Down
16 changes: 13 additions & 3 deletions src/export_renderers.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -48,9 +55,12 @@ callWithJQuery ($) ->
result.push row
text = ""
for r in result
text += r.join("\t")+"\n"
text += r.join(separator)+"\n"

return $("<textarea>").text(text).css(
width: ($(window).width() / 2) + "px",
height: ($(window).height() / 2) + "px")

$.pivotUtilities.export_renderers =
"TSV Export": (pivotData, opts) -> svExporter(pivotData, opts, "tsv"),
"CSV Export": (pivotData, opts) -> svExporter(pivotData, opts, "csv")

0 comments on commit f6451af

Please sign in to comment.