forked from nicolaskruchten/pivottable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_renderers.coffee
57 lines (46 loc) · 1.65 KB
/
export_renderers.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
callWithJQuery = (pivotModule) ->
if typeof exports is "object" and typeof module is "object" # CommonJS
pivotModule require("jquery")
else if typeof define is "function" and define.amd # AMD
define ["jquery"], pivotModule
# Plain browser env
else
pivotModule jQuery
callWithJQuery ($) ->
$.pivotUtilities.export_renderers = "TSV Export": (pivotData, opts) ->
defaults =
localeStrings: {}
opts = $.extend defaults, opts
rowKeys = pivotData.getRowKeys()
rowKeys.push [] if rowKeys.length == 0
colKeys = pivotData.getColKeys()
colKeys.push [] if colKeys.length == 0
rowAttrs = pivotData.rowAttrs
colAttrs = pivotData.colAttrs
result = []
row = []
for rowAttr in rowAttrs
row.push rowAttr
if colKeys.length == 1 and colKeys[0].length == 0
row.push pivotData.aggregatorName
else
for colKey in colKeys
row.push colKey.join("-")
result.push row
for rowKey in rowKeys
row = []
for r in rowKey
row.push r
for colKey in colKeys
agg = pivotData.getAggregator(rowKey, colKey)
if agg.value()?
row.push agg.value()
else
row.push ""
result.push row
text = ""
for r in result
text += r.join("\t")+"\n"
return $("<textarea>").text(text).css(
width: ($(window).width() / 2) + "px",
height: ($(window).height() / 2) + "px")