Skip to content

Commit 46e48f0

Browse files
lpt.getRowsValues, lpt.getModel, lpt.triggers.rowClick, lpt.triggers.rowSelect add
1 parent 16fbb08 commit 46e48f0

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "LightPivotTable",
33
"author": "ZitRo",
4-
"version": "1.7.1",
4+
"version": "1.7.4",
55
"description": "A lightweight pivot table for MDX2JSON source for InterSystems Cache",
66
"main": "test/testServer.js",
77
"repository": {

readme.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ var setup = { // Object that contain settings. Properties in brackets can be mis
5353
// if cellDrillThrough callback returns boolean false, DrillThrough won't be performed.
5454
, cellDrillThrough: function ({Object { event: {event}, filters: {string[]}, cellData: {object} }}) {}
5555
, responseHandler: function ({Object {url: {string}, status: {number}}}) {}
56-
, rowSelect: function ({Array}) {}
56+
// triggers when row selected in listing:
57+
, rowSelect: function (row, rowData) { console.log("Row #", row, rowData); }
58+
// if rowClick callback returns boolean false, DrillDown won't be performed.
59+
, rowClick: function (row, rowData) { console.log(row, rowData); }
5760
, contentRendered: function () {}
5861
, cellSelected: function ({ x: Number, y: Number, leftHeaderColumnsNumber: Number, topHeaderRowsNumber: Number }) {
5962
return false; // return false to block default click action
@@ -98,6 +101,8 @@ lp.refresh(); // refresh pivot contents
98101
lp.updateSizes(); // recalculate pivot sizes
99102
lp.changeBasicMDX("..."); // change mdx for LPT
100103
lp.getActualMDX(); // returns currently displayed MDX
104+
var rows = lp.getRowsValues([1,2,3]); // returns the values in rows 1, 2, 3
105+
var model = lp.getModel(); // returns data model representing currently rendered data set
101106
lp.getSelectedRows(); // returns array with selected rows indexes. First row have index 1.
102107
lp.attachTrigger("contentRendered", function (lptInstance) { }); // attaches trigger during runtime
103108
lp.setRowCount(5); // sets the number of rows to display

source/js/LightPivotTable.js

+27
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,33 @@ LightPivotTable.prototype.getSelectedRows = function () {
144144

145145
};
146146

147+
/**
148+
* Return array of passed rows values.
149+
* @param {Number[]} rows - Rows indices in the table. Index 1 points to the first row with data.
150+
* @returns {*[]}
151+
*/
152+
LightPivotTable.prototype.getRowsValues = function (rows) {
153+
if (typeof rows === "undefined")
154+
return [];
155+
if (!(rows instanceof Array))
156+
rows = [rows];
157+
if (rows.length === 0)
158+
return [];
159+
var d = this.dataController.getData(),
160+
arr = [];
161+
for (var i = 0; i < rows.length; i++) {
162+
arr.push(d.rawData[rows[i] - 1 + (d.info.topHeaderRowsNumber || 1)]);
163+
}
164+
return arr;
165+
};
166+
167+
/**
168+
* Returns currently rendered model.
169+
*/
170+
LightPivotTable.prototype.getModel = function () {
171+
return this.dataController.getData();
172+
};
173+
147174
/**
148175
* Performs resizing.
149176
*/

source/js/PivotView.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,15 @@ PivotView.prototype._columnClickHandler = function (columnIndex) {
364364

365365
PivotView.prototype._rowClickHandler = function (rowIndex, cellData) {
366366

367-
this.controller.tryDrillDown(cellData.source.path);
367+
var res = true;
368+
if (typeof this.controller.CONFIG.triggers["rowClick"] === "function") {
369+
var d = this.controller.getRowsValues([rowIndex])[0].slice(
370+
this.controller.dataController.getData().info.leftHeaderColumnsNumber
371+
);
372+
res = this.controller.CONFIG.triggers["rowClick"](rowIndex, d);
373+
}
374+
if (res !== false)
375+
this.controller.tryDrillDown(cellData.source.path);
368376

369377
};
370378

@@ -727,7 +735,11 @@ PivotView.prototype.selectRow = function (select, rowNumber) {
727735
delete this.selectedRows[rowNumber];
728736

729737
if (typeof this.controller.CONFIG.triggers["rowSelect"] === "function") {
730-
this.controller.CONFIG.triggers["rowSelect"](this.controller.getSelectedRows());
738+
var rows = this.controller.getSelectedRows();
739+
this.controller.CONFIG.triggers["rowSelect"](
740+
rows,
741+
this.controller.getRowsValues(rows)
742+
);
731743
}
732744

733745
};

0 commit comments

Comments
 (0)