|
11 | 11 |
|
12 | 12 | <Class name="DeepSee.LightPivotTable"> |
13 | 13 | <Super>%DeepSee.Component.Portlet.abstractPortlet</Super> |
14 | | - <TimeChanged>63531,82258.204784</TimeChanged> |
| 14 | + <TimeChanged>63544,74499.681602</TimeChanged> |
15 | 15 | <TimeCreated>63515,61322.546099</TimeCreated> |
16 | 16 |
|
17 | 17 | <Parameter name="INCLUDEFILES"> |
|
22 | 22 | <Type>%String</Type> |
23 | 23 | </Property> |
24 | 24 |
|
| 25 | + <Property name="ExportCSV"> |
| 26 | + <Type>%Boolean</Type> |
| 27 | + </Property> |
| 28 | + |
25 | 29 | <Property name="ShowSummary"> |
26 | 30 | <Type>%Boolean</Type> |
27 | 31 | </Property> |
|
48 | 52 | kill pInfo // $LB(name,value,type,caption,title) |
49 | 53 |
|
50 | 54 | set pInfo($I(pInfo)) = $LB("DataSource", "/" _ $NAMESPACE, "%String", $$$Text("MDX2JSON source", "%DeepSee"), "Set the URL of MDX2JSON source. Example: ""/SAMPLES""") |
51 | | - set pInfo($I(pInfo)) = $LB("ShowSummary", 1, "%Boolean", $$$Text("Show summary?", "%DeepSee"), "Show summary row") |
| 55 | + set pInfo($I(pInfo)) = $LB("ShowSummary", 1, "%Boolean", $$$Text("Show summary", "%DeepSee"), "Show summary row") |
| 56 | + set pInfo($I(pInfo)) = $LB("ExportCSV", 1, "%Boolean", $$$Text("Export to CSV", "%DeepSee"), "Show export to CSV format button") |
52 | 57 |
|
53 | 58 | quit $$$OK |
54 | 59 | ]]></Implementation> |
|
105 | 110 | <ClientMethod>1</ClientMethod> |
106 | 111 | <Implementation><![CDATA[ |
107 | 112 | var container = document.getElementById(this.id), |
108 | | - controller, |
| 113 | + basicContainer = container, |
| 114 | + self = this; |
| 115 | +
|
| 116 | + if (!container) { |
| 117 | + console.error("Light pivot table: Unable to get widget with ID=" + this.id); |
| 118 | + setTimeout(function () { self.onCreate.call(self); }, 1); |
| 119 | + return; |
| 120 | + } |
| 121 | +
|
| 122 | + for (i in container.childNodes) { |
| 123 | + if (container.childNodes[i].className === "lpt-container") { |
| 124 | + container = container.childNodes[i]; |
| 125 | + break; |
| 126 | + } |
| 127 | + } |
| 128 | +
|
| 129 | + var controller, |
109 | 130 | source, |
110 | 131 | setup, |
111 | 132 | _ = this, |
112 | 133 | widget = this, // It's lie. It changes later. |
113 | 134 | widgetKey, |
114 | | - i, info = {}; |
| 135 | + i, info = {}, |
| 136 | + exportToExcel = !!parseInt(container.getAttribute("export-csv")); |
| 137 | +
|
| 138 | + if (exportToExcel) { |
| 139 | + var widgetHead = document.getElementById(basicContainer.getAttribute("id").replace(/\/.*/, "/header")); |
| 140 | + if (widgetHead) { |
| 141 | + var f, |
| 142 | + widgetTr = (f = function (el) {var r; if (el.tagName === "TR") return el; for (var i in el.childNodes) { r = f(el.childNodes[i]); if (r) return r; } return null; })(widgetHead); |
| 143 | + if (widgetTr) { |
| 144 | + var td = document.createElement("TD"); |
| 145 | + td.selfW = _; |
| 146 | + td.setAttribute("style", "padding-right:6px;vertical-align:bottom;"); |
| 147 | + td.innerHTML = "<div class=\"zendiv\" onclick=\"this.parentNode.selfW.exportCSV.call(this.parentNode.selfW)\"><img class=\"imageLink\" src=\"deepsee/ds2_action_44.png\" title=\"Export to CSV format\"></div>"; |
| 148 | + widgetTr.appendChild(td); |
| 149 | + } |
| 150 | + } |
| 151 | + } |
115 | 152 |
|
116 | 153 | var post = function (url, data, callback) { |
117 | 154 |
|
|
138 | 175 |
|
139 | 176 | }; |
140 | 177 |
|
141 | | - if (!container) { |
142 | | - console.error("Light pivot table: Unable to get widget with ID=" + this.id); |
143 | | - return; |
144 | | - } |
145 | | -
|
146 | | - for (i in container.childNodes) { |
147 | | - if (container.childNodes[i].className === "lpt-container") { |
148 | | - container = container.childNodes[i]; |
149 | | - break; |
150 | | - } |
151 | | - } |
152 | | -
|
153 | 178 | setTimeout(function() { // onCreate fired when scripts are ready, but this.parent is missed. |
154 | 179 |
|
155 | 180 | controller = _.getConnectedController(); |
|
195 | 220 | ]]></Implementation> |
196 | 221 | </Method> |
197 | 222 |
|
| 223 | + <Method name="exportCSV"> |
| 224 | + <Description> |
| 225 | + Firing this method will cause CSV-file download</Description> |
| 226 | + <Language>javascript</Language> |
| 227 | + <ClientMethod>1</ClientMethod> |
| 228 | + <Implementation><![CDATA[ |
| 229 | + if (!this.LightPivotTable) return; |
| 230 | + //console.log(this.LightPivotTable); |
| 231 | + var link = document.createElement("a"), |
| 232 | + csvData = [], |
| 233 | + rawData = this.LightPivotTable.dataController.getData(), |
| 234 | + row, cell; |
| 235 | +
|
| 236 | + if (!rawData || !(rawData.rawData instanceof Array)) return; |
| 237 | + rawData = rawData.rawData; |
| 238 | +
|
| 239 | + for (var y = 0; y < rawData.length; y++) { |
| 240 | + row = []; |
| 241 | + for (var x = 0; x < rawData[y].length; x++) { |
| 242 | + cell = (rawData[y][x].value || "").toString(); |
| 243 | + if (isFinite(cell)) cell = cell.replace(/\./g, ","); |
| 244 | + if (cell.indexOf("\"") > -1 || cell.indexOf(";") > -1) { |
| 245 | + cell = "\"" + cell.replace(/"/g, "\"\"") + "\""; |
| 246 | + } |
| 247 | + row.push(cell); |
| 248 | + } |
| 249 | + csvData.push(row.join(";")); |
| 250 | + } |
| 251 | +
|
| 252 | + link.setAttribute("href", "data:application/csv;charset=UTF-8,\uFEFF"+encodeURIComponent(csvData.join("\r\n"))); |
| 253 | + link.setAttribute("download", "EXPORT.csv"); |
| 254 | + link.click(); |
| 255 | +]]></Implementation> |
| 256 | + </Method> |
| 257 | + |
198 | 258 | <Method name="%DrawHTML"> |
199 | 259 | <Implementation><![CDATA[ |
200 | 260 | set ..renderFlag = ..renderFlag + 1 |
|
214 | 274 | } |
215 | 275 |
|
216 | 276 | &html< |
217 | | - <div data-source="#(..DataSource)#" show-summary="#(..ShowSummary)#" class="lpt-container" style="position: absolute; left: 0; bottom: 0; width: 100%; height: 100%;"> |
| 277 | + <div export-csv="#(..ExportCSV)#" data-source="#(..DataSource)#" show-summary="#(..ShowSummary)#" class="lpt-container" style="position: absolute; left: 0; bottom: 0; width: 100%; height: 100%;"> |
218 | 278 |
|
219 | 279 | </div> |
220 | 280 | > |
|
0 commit comments