Skip to content

Commit 6e11c89

Browse files
cellDrillThrough callback & customDrillThrough control add
1 parent 1be0107 commit 6e11c89

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

example/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
// drillDown: function ({Object { level: {number}, mdx: {string} }}) {}
9898
//, drillThrough: function ({Object { level: {number}, mdx: {string} }}) {}
9999
//, back: function ({Object { level: {number} }}) {}
100+
//, cellDrillThrough: function ({Object { event: {event}, filters: {string[]} }}) {}
100101
}
101102
//, hideButtons: true // hides "back" and "drillThrough" buttons
102103
//, triggerEvent: "touchstart" // all "click" events will be replaced by this event

readme.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ var setup = { // Object that contain settings. Any setting may be missed.
4646
drillDown: function ({Object { level: {number}, mdx: {string} }}) {}
4747
, drillThrough: function ({Object { level: {number}, mdx: {string} }}) {}
4848
, back: function ({Object { level: {number} }}) {}
49+
// if cellDrillThrough callback returns boolean false, DrillThrough won't be performed.
50+
, cellDrillThrough: function ({Object { event: {event}, filters: {string[]} }}) {}
4951
} ]
5052
[ , hideButtons: true // hides "back" and "drillThrough" buttons ]
5153
[ , triggerEvent: "touchstart" // all "click" events will be replaced by this event ]
@@ -56,6 +58,11 @@ var setup = { // Object that contain settings. Any setting may be missed.
5658
lp = new LightPivotTable(setup);
5759

5860
console.log(lp.CONTROLS); // object with functions that can be triggered to control pivot table
61+
/* Available controls:
62+
* lp.CONTROLS.drillThrough() - Perform drillThrough for current location.
63+
* lp.CONTROLS.customDrillThrough(["filterSpec1", ...]) - Perform drillThrough with filters.
64+
* lp.CONTROLS.back() - Back to the parent level.
65+
*/
5966

6067
lp.setFilter("[DateOfSale].[Actual].[YearSold].&[2009]");
6168
lp.refresh();

source/js/LightPivotTable.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,14 @@ LightPivotTable.prototype.init = function () {
246246
_.pivotView._drillThroughClickHandler.call(_.pivotView);
247247
};
248248

249+
this.CONTROLS.customDrillThrough = function (filters) {
250+
if (!(filters instanceof Array)) {
251+
console.error("Parameter \"filters\" must be array of strings.");
252+
return;
253+
}
254+
_.tryDrillThrough.call(_, filters);
255+
};
256+
249257
this.CONTROLS.back = function () {
250258
_.pivotView._backClickHandler.call(_.pivotView);
251259
};

source/js/PivotView.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,15 @@ PivotView.prototype._drillThroughClickHandler = function (event) {
171171

172172
};
173173

174-
PivotView.prototype._cellClickHandler = function (x, y) {
174+
/**
175+
* @param {number} x
176+
* @param {number} y
177+
* @param {event} event
178+
*/
179+
PivotView.prototype._cellClickHandler = function (x, y, event) {
175180

176181
var data = this.controller.dataController.getData(),
177-
f = [], f1, f2;
182+
f = [], f1, f2, callbackRes;
178183

179184
try {
180185
f1 = data.rawData[y][data.info.leftHeaderColumnsNumber - 1].source.path;
@@ -191,7 +196,15 @@ PivotView.prototype._cellClickHandler = function (x, y) {
191196
+ encodeURIComponent(this.controller.CONFIG["drillDownTarget"]) + "&SETTINGS=FILTER:"
192197
+ encodeURIComponent(f.join("~")) + ";";
193198
} else {
194-
this.controller.tryDrillThrough(f);
199+
if (typeof this.controller.CONFIG.triggers["cellDrillThrough"] === "function") {
200+
callbackRes = this.controller.CONFIG.triggers["cellDrillThrough"]({
201+
event: event,
202+
filters: f
203+
});
204+
if (callbackRes !== false) this.controller.tryDrillThrough(f);
205+
} else {
206+
this.controller.tryDrillThrough(f);
207+
}
195208
}
196209

197210
};
@@ -535,8 +548,8 @@ PivotView.prototype.renderRawData = function (data) {
535548
span.textContent = data[y][x].value;
536549
}
537550

538-
(function (x, y) {addTrigger(td, clickEvent, function () {
539-
_._cellClickHandler.call(_, x, y);
551+
(function (x, y) {addTrigger(td, clickEvent, function (event) {
552+
_._cellClickHandler.call(_, x, y, event);
540553
})})(x, y);
541554
} else {
542555
span.textContent = data[y][x].value;

0 commit comments

Comments
 (0)