Skip to content

Commit ef24865

Browse files
fixed filters increment on refresh, docs provided
1 parent 53ef15f commit ef24865

5 files changed

Lines changed: 15 additions & 126 deletions

File tree

example/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
, enableHeadersScrolling: true // enable scrolling both for table and headers
110110
//, loadingMessageHTML: "LOADING DATA..." // HTML displaying during data load
111111
//, conditionalFormattingOn: true // enable conditional formatting rules
112+
//, defaultFilterSpecs: ["[Date].[H1].[month].&[]"] ] // default filters array
112113
//, drillDownTarget: "<dashboard name>" // undocumented, deepSee only
113114
};
114115

export/LightPivotTable-DeepSeePortlet.xml

Lines changed: 5 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<Class name="DeepSee.LightPivotTable">
1313
<Super>%DeepSee.Component.Portlet.abstractPortlet</Super>
14-
<TimeChanged>63565,62684.158342</TimeChanged>
14+
<TimeChanged>63565,64700.290542</TimeChanged>
1515
<TimeCreated>63515,61322.546099</TimeCreated>
1616

1717
<Parameter name="INCLUDEFILES">
@@ -88,11 +88,11 @@
8888
// prevents refreshing twice at start
8989
if (!this._INITIALIZED) { this._INITIALIZED = true; return; }
9090
91-
this.LightPivotTable.clearFilters();
91+
this.LightPivotTable.CONFIG["defaultFilterSpecs"] = [];
9292
9393
// updateFilters
9494
for (var i in controller.filters) {
95-
this.LightPivotTable.setFilter(controller.filters[i].spec);
95+
this.LightPivotTable.CONFIG["defaultFilterSpecs"].push(controller.filters[i].spec);
9696
}
9797
9898
this.LightPivotTable.refresh();
@@ -108,13 +108,6 @@
108108
]]></Implementation>
109109
</Method>
110110

111-
<Method name="onRefreshContents">
112-
<Language>javascript</Language>
113-
<ClientMethod>1</ClientMethod>
114-
<Implementation><![CDATA[ console.log("onRefreshContents", this);
115-
]]></Implementation>
116-
</Method>
117-
118111
<Method name="InitLPT">
119112
<Language>javascript</Language>
120113
<ClientMethod>1</ClientMethod>
@@ -125,7 +118,6 @@
125118
126119
if (!container) {
127120
console.error("Light pivot table: Unable to get widget with ID=" + this.id);
128-
setTimeout(function () { self.onCreate.call(self); }, 1);
129121
return;
130122
}
131123
@@ -146,11 +138,11 @@
146138
defaultFilters = [],
147139
exportToExcel = !!parseInt(container.getAttribute("export-csv"));
148140
149-
// !ultra-bydlocode (get the widget object)
141+
// !ultra-bydlocode (get the widget object)
150142
while (widget["parent"]) {
151143
widget = widget["parent"];
152144
}
153-
// !ultra-bydlocode (possible you will have better suggestions to get widget key)
145+
// !ultra-bydlocode (possible you will have better suggestions to get widget key)
154146
widgetKey = parseInt(_.parent.parent.onwindowgrab.match(/[0-9]+/)[0]);
155147
156148
if (exportToExcel) {
@@ -247,114 +239,6 @@
247239
// filtering frequent size updates as an expensive operation
248240
this._SIZE_ADJUST_TIMEOUT = 0;
249241
this._FIRST_TIME_SIZE_UPDATE = true;
250-
/*var container = document.getElementById(this.id),
251-
basicContainer = container,
252-
self = this;
253-
254-
if (!container) {
255-
console.error("Light pivot table: Unable to get widget with ID=" + this.id);
256-
setTimeout(function () { self.onCreate.call(self); }, 1);
257-
return;
258-
}
259-
260-
for (i in container.childNodes) {
261-
if (container.childNodes[i].className === "lpt-container") {
262-
container = container.childNodes[i];
263-
break;
264-
}
265-
}
266-
267-
var controller,
268-
source,
269-
setup,
270-
_ = this,
271-
widget = this, // It's lie. It changes later.
272-
widgetKey,
273-
i, info = {},
274-
exportToExcel = !!parseInt(container.getAttribute("export-csv"));
275-
276-
if (exportToExcel) {
277-
var widgetHead = document.getElementById(basicContainer.getAttribute("id").replace(/\/./, "/header"));
278-
if (widgetHead) {
279-
var f,
280-
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);
281-
if (widgetTr) {
282-
var td = document.createElement("TD");
283-
td.selfW = _;
284-
td.setAttribute("style", "padding-right:6px;vertical-align:bottom;");
285-
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>";
286-
widgetTr.appendChild(td);
287-
}
288-
}
289-
}
290-
291-
var post = function (url, data, callback) {
292-
293-
var xhr = new XMLHttpRequest();
294-
xhr.open("POST", url);
295-
xhr.onreadystatechange = function () {
296-
if (xhr.readyState === 4 && xhr.status === 200) {
297-
callback((function () {
298-
try {
299-
return JSON.parse(xhr.responseText) || {}
300-
} catch (e) {
301-
return {
302-
error: "<h1>Unable to parse server response</h1><p>" + xhr.responseText
303-
+ "</p>"
304-
};
305-
}
306-
})());
307-
} else if (xhr.readyState === 4 && xhr.status !== 200) {
308-
callback({ error: xhr.responseText
309-
|| "Error while trying to retrieve data from server." });
310-
}
311-
};
312-
xhr.send(JSON.stringify(data));
313-
314-
};
315-
316-
setTimeout(function() { // onCreate fired when scripts are ready, but this.parent is missed.
317-
318-
controller = _.getConnectedController();
319-
320-
// !ultra-bydlocode (get the widget object)
321-
while (widget["parent"]) {
322-
widget = widget["parent"];
323-
}
324-
// !ultra-bydlocode (possible you will have better suggestions to get widget key)
325-
widgetKey = parseInt(_.parent.parent.onwindowgrab.match(/[0-9]+/)[0]);
326-
327-
post((source = location.origin + container.getAttribute("data-source")) + "/Widgets", {
328-
Dashboard: widget["dashboardName"]
329-
}, function (data) {
330-
if (data.error) {
331-
container.innerHTML = "<br/><br/><h3>Unable to get data from server.</h3><p>Check if data source is configured and accessible: " + source + "/Widgets" + "</p>"
332-
} else {
333-
for (i in data.children) {
334-
if (data.children[i].key === widgetKey) {
335-
info = data.children[i];
336-
break;
337-
}
338-
}
339-
//console.log(info);
340-
setup = {
341-
container: container,
342-
dataSource: {
343-
pivot: info["dataSource"],
344-
MDX2JSONSource: source,
345-
basicMDX: info["mdx"]
346-
}
347-
}
348-
if (controller && controller["data"] && controller["data"]["rowCaptions"] && typeof controller["data"]["rowCaptions"][0] === "string") setup.caption = controller["data"]["rowCaptions"][0];
349-
if (controller && controller["data"] && !setup.caption) setup.caption = controller["data"]["defaultCaption"] || "";
350-
if (info["drillDownDataSource"]) setup["drillDownTarget"] = info["drillDownDataSource"];
351-
setup["showSummary"] = !!parseInt(container.getAttribute("show-summary"));
352-
353-
_.LightPivotTable = new LightPivotTable(setup);
354-
}
355-
});
356-
357-
}, 0);*/
358242
]]></Implementation>
359243
</Method>
360244

readme.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,17 @@ var setup = { // Object that contain settings. Any setting may be missed.
6464
},
6565
lp = new LightPivotTable(setup);
6666

67-
console.log(lp.CONTROLS); // object with functions that can be triggered to control pivot table
67+
console.log(lp.CONTROLS); // object with functions that can be triggered to control pivot table:
6868
/* Available controls:
6969
* lp.CONTROLS.drillThrough() - Perform drillThrough for current location.
7070
* lp.CONTROLS.customDrillThrough(["filterSpec1", ...]) - Perform drillThrough with filters.
7171
* lp.CONTROLS.back() - Back to the parent level.
7272
*/
7373

7474
lp.setFilter("[DateOfSale].[Actual].[YearSold].&[2009]");
75-
lp.refresh();
75+
76+
lp.refresh(); // refresh pivot contents
77+
lp.updateSizes(); // recalculate pivot sizes
7678
```
7779

7880
#### Caché DeepSee

source/js/DataSource.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var DataSource = function (config, globalConfig, lpt) {
2828

2929
this.FILTERS = [];
3030

31-
this.BASIC_FILTERS = [];
31+
this._PIVOT_DEFAULT_FILTERS = [];
3232

3333
};
3434

@@ -130,6 +130,7 @@ DataSource.prototype.getCurrentData = function (callback) {
130130
var data = ready.pivotData;
131131

132132
_.GLOBAL_CONFIG["pivotProperties"] = ready.pivotData;
133+
_._PIVOT_DEFAULT_FILTERS = [];
133134

134135
if (data["rowAxisOptions"]) {
135136
if (data["rowAxisOptions"]["drilldownSpec"]) {
@@ -150,7 +151,7 @@ DataSource.prototype.getCurrentData = function (callback) {
150151
if (data["filters"] && data["filters"].length > 0) {
151152
for (var i in data["filters"]) {
152153
if (data["filters"][i]["spec"]) {
153-
_.BASIC_FILTERS.push(data["filters"][i]["spec"]);
154+
_._PIVOT_DEFAULT_FILTERS.push(data["filters"][i]["spec"]);
154155
}
155156
}
156157
}
@@ -211,7 +212,7 @@ DataSource.prototype.getCurrentData = function (callback) {
211212

212213
var requestData = function () {
213214

214-
var filters = _.BASIC_FILTERS.concat(_.FILTERS);
215+
var filters = _._PIVOT_DEFAULT_FILTERS.concat(_.FILTERS);
215216

216217
for (var i in filters) {
217218
mdx = mdxParser.applyFilter(mdx, filters[i]);

source/js/LightPivotTable.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ LightPivotTable.prototype.refresh = function () {
5050
var _ = this,
5151
i;
5252

53+
this.clearFilters();
5354
if (this.CONFIG["defaultFilterSpecs"] instanceof Array) {
5455
for (i in this.CONFIG["defaultFilterSpecs"]) {
5556
this.setFilter(this.CONFIG["defaultFilterSpecs"][i]);

0 commit comments

Comments
 (0)