Skip to content

Commit 0f34f61

Browse files
drillthrough fixes, drillthrough for cells
1 parent 49b51f7 commit 0f34f61

File tree

5 files changed

+72
-18
lines changed

5 files changed

+72
-18
lines changed

example/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
<a onclick="rSoon(this)">6</a>,
3636
<a onclick="rSoon(this)">7</a>,
3737
<a onclick="rSoon(this)">8</a>,
38-
<a onclick="rSoon(this)">9</a>
38+
<a onclick="rSoon(this)">9</a>,
39+
<a onclick="rSoon(this)">10</a>
3940
</div>
4041
<div id="mdx"></div>
4142
<form id="mdxForm" onsubmit="return false;">
@@ -64,6 +65,7 @@
6465
"SELECT NON EMPTY [Product].[P1].[Product Category].Members ON 0,{[Measures].[%COUNT]} ON 1 FROM [HoleFoods] %FILTER [Measures].[%COUNT]",
6566
"SELECT NON EMPTY [Product].[P1].[Product Category].Members ON 0, NON EMPTY [Outlet].[H1].[Region].Members ON 1 FROM [HoleFoods]",
6667
"SELECT NON EMPTY [Product].[P1].[Product Category].Members ON 0,NON EMPTY [DateOfSale].[Actual].[YearSold].&[2010].children ON 1 FROM [HoleFoods] %FILTER [DateOfSale].[Actual].[YearSold].&[2010] %FILTER [Measures].[%COUNT]",
68+
"SELECT NON EMPTY [Product].[P1].[Product Category].Members ON 0,NON EMPTY [DateOfSale].[Actual].[YearSold].Members ON 1 FROM [HoleFoods]",
6769
"SELECT NON EMPTY [Product].[P1].[Product Category].Members ON 0,NON EMPTY [DateOfSale].[Actual].[YearSold].Members ON 1 FROM [HoleFoods]"
6870
][v];
6971

source/css/LightPivot.css

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,20 +177,20 @@
177177
background: #e2c8ff;
178178
}
179179

180-
.orderedDec {
181-
background: red;
182-
}
183-
184-
.orderedAsc {
185-
background: orange;
186-
}
187-
188180
.lpt td {
189181
background: #E1E8FF;
182+
-webkit-transition: all .3s ease;
183+
-moz-transition: all .3s ease;
184+
-o-transition: all .3s ease;
185+
transition: all .3s ease;
190186
}
191187

192188
.lpt tr:hover td {
193-
background: #FFDEBF;
189+
background: #ffe6cf;
190+
}
191+
192+
.lpt table td:hover {
193+
background: #e2c8ff;
194194
}
195195

196196
.lpt tbody > tr > th {

source/js/LightPivotTable.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,24 @@ LightPivotTable.prototype.tryDrillDown = function (filter) {
9191

9292
};
9393

94-
LightPivotTable.prototype.showDrillThrough = function () {
94+
/**
95+
* @param {string[]} [filters]
96+
*/
97+
LightPivotTable.prototype.showDrillThrough = function (filters) {
9598

9699
var _ = this,
97100
ds = {};
98101

99102
// clone dataSource config object
100103
for (var i in _.CONFIG.dataSource) { ds[i] = _.CONFIG.dataSource[i]; }
101104
ds.action = "MDXDrillthrough";
102-
ds.basicMDX = this.mdxParser.drillThrough(ds.basicMDX) || ds.basicMDX;
105+
if (filters instanceof Array) {
106+
ds.basicMDX = this.mdxParser.customDrillThrough(this.dataSource.BASIC_MDX, filters)
107+
|| this.dataSource.basicMDX;
108+
} else {
109+
ds.basicMDX = this.dataSource.BASIC_MDX;
110+
ds.basicMDX = this.mdxParser.drillThrough(ds.basicMDX) || ds.basicMDX;
111+
}
103112

104113
this.pushDataSource(ds);
105114

source/js/MDXParser.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,23 @@ MDXParser.prototype.drillThrough = function (basicMDX) {
5858

5959
}
6060

61+
};
62+
63+
/**
64+
* @param {string} basicMDX
65+
* @param {string[]} filters
66+
*/
67+
MDXParser.prototype.customDrillThrough = function (basicMDX, filters) {
68+
69+
var cubeName = basicMDX.split(/FROM\s*\[([^\]]*)]/i)[1],
70+
query = "DRILLTHROUGH SELECT FROM [" + cubeName + "]";
71+
72+
if (!(filters instanceof Array)) filters = [filters];
73+
74+
for (var i in filters) {
75+
query += " %FILTER " + filters[i];
76+
}
77+
78+
return query;
79+
6180
};

source/js/PivotView.js

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ PivotView.prototype._rowClickHandler = function (rowIndex, cellData) {
134134

135135
};
136136

137-
PivotView.prototype._backClickHandler = function () {
137+
PivotView.prototype._backClickHandler = function (event) {
138+
139+
event.cancelBubble = true;
140+
event.stopPropagation();
138141

139142
this.popTable();
140143
this.controller.popDataSource();
@@ -150,6 +153,22 @@ PivotView.prototype._drillThroughClickHandler = function (event) {
150153

151154
};
152155

156+
PivotView.prototype._cellClickHandler = function (x, y) {
157+
158+
var data = this.controller.dataController.getData(),
159+
f1, f2;
160+
161+
try {
162+
f1 = data.rawData[y][data.info.leftHeaderColumnsNumber - 1].source.path;
163+
f2 = data.rawData[data.info.topHeaderRowsNumber - 1][x].source.path;
164+
} catch (e) {
165+
console.warn("Unable to get filters for cell (%d, %d)", x, y);
166+
}
167+
168+
this.controller.showDrillThrough([f1, f2]);
169+
170+
};
171+
153172
PivotView.prototype.fixSizes = function (baseElement, elementToFix) {
154173

155174
if (!elementToFix.style) return false;
@@ -242,8 +261,9 @@ PivotView.prototype.fixHeaders = function (tableElement) {
242261

243262
// add scroll listener
244263
tableElement.parentNode.addEventListener("scroll", this._scrollListener = function () {
245-
hHead.style.top = fhx.style.top = tableElement.parentNode.scrollTop + "px";
246-
hHead.style.left = fhy.style.left = tableElement.parentNode.scrollLeft + "px";
264+
if (!tableElement.parentNode) return; // toFix
265+
hHead.style.top = fhx.style.top = tableElement.parentNode.scrollTop + "px";
266+
hHead.style.left = fhy.style.left = tableElement.parentNode.scrollLeft + "px";
247267
}, false);
248268

249269
// append new elements
@@ -379,8 +399,8 @@ PivotView.prototype.renderRawData = function (data) {
379399
if (x === 0 && y === 0 && _.tablesStack.length > 1) {
380400
var elt = document.createElement("div");
381401
elt.className = "backButton";
382-
addTrigger(elt, "click", function () {
383-
_._backClickHandler.call(_);
402+
addTrigger(elt, "click", function (event) {
403+
_._backClickHandler.call(_, event);
384404
});
385405
td.insertBefore(elt, td.childNodes[td.childNodes.length - 1] || null);
386406
}
@@ -415,8 +435,12 @@ PivotView.prototype.renderRawData = function (data) {
415435
var span = document.createElement("span");
416436
span.textContent = data[y][x].value;
417437
td.appendChild(span);
418-
//td.textContent = ;
419438
tr.appendChild(td);
439+
if (x >= headLeftColsNum && y >= headRowsNum) {
440+
(function (x, y) {addTrigger(td, "click", function () {
441+
_._cellClickHandler.call(_, x, y);
442+
})})(x, y);
443+
}
420444
}
421445

422446
if (x === 0 && y === 0 && _.controller.dataController.getData().info.action === "MDX") {

0 commit comments

Comments
 (0)