Skip to content

Commit

Permalink
lpt.getRowsValues, lpt.getModel, lpt.triggers.rowClick, lpt.triggers.…
Browse files Browse the repository at this point in the history
…rowSelect add
  • Loading branch information
nikitaeverywhere committed Feb 10, 2017
1 parent 16fbb08 commit 46e48f0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "LightPivotTable",
"author": "ZitRo",
"version": "1.7.1",
"version": "1.7.4",
"description": "A lightweight pivot table for MDX2JSON source for InterSystems Cache",
"main": "test/testServer.js",
"repository": {
Expand Down
7 changes: 6 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ var setup = { // Object that contain settings. Properties in brackets can be mis
// if cellDrillThrough callback returns boolean false, DrillThrough won't be performed.
, cellDrillThrough: function ({Object { event: {event}, filters: {string[]}, cellData: {object} }}) {}
, responseHandler: function ({Object {url: {string}, status: {number}}}) {}
, rowSelect: function ({Array}) {}
// triggers when row selected in listing:
, rowSelect: function (row, rowData) { console.log("Row #", row, rowData); }
// if rowClick callback returns boolean false, DrillDown won't be performed.
, rowClick: function (row, rowData) { console.log(row, rowData); }
, contentRendered: function () {}
, cellSelected: function ({ x: Number, y: Number, leftHeaderColumnsNumber: Number, topHeaderRowsNumber: Number }) {
return false; // return false to block default click action
Expand Down Expand Up @@ -98,6 +101,8 @@ lp.refresh(); // refresh pivot contents
lp.updateSizes(); // recalculate pivot sizes
lp.changeBasicMDX("..."); // change mdx for LPT
lp.getActualMDX(); // returns currently displayed MDX
var rows = lp.getRowsValues([1,2,3]); // returns the values in rows 1, 2, 3
var model = lp.getModel(); // returns data model representing currently rendered data set
lp.getSelectedRows(); // returns array with selected rows indexes. First row have index 1.
lp.attachTrigger("contentRendered", function (lptInstance) { }); // attaches trigger during runtime
lp.setRowCount(5); // sets the number of rows to display
Expand Down
27 changes: 27 additions & 0 deletions source/js/LightPivotTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,33 @@ LightPivotTable.prototype.getSelectedRows = function () {

};

/**
* Return array of passed rows values.
* @param {Number[]} rows - Rows indices in the table. Index 1 points to the first row with data.
* @returns {*[]}
*/
LightPivotTable.prototype.getRowsValues = function (rows) {
if (typeof rows === "undefined")
return [];
if (!(rows instanceof Array))
rows = [rows];
if (rows.length === 0)
return [];
var d = this.dataController.getData(),
arr = [];
for (var i = 0; i < rows.length; i++) {
arr.push(d.rawData[rows[i] - 1 + (d.info.topHeaderRowsNumber || 1)]);
}
return arr;
};

/**
* Returns currently rendered model.
*/
LightPivotTable.prototype.getModel = function () {
return this.dataController.getData();
};

/**
* Performs resizing.
*/
Expand Down
16 changes: 14 additions & 2 deletions source/js/PivotView.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,15 @@ PivotView.prototype._columnClickHandler = function (columnIndex) {

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

this.controller.tryDrillDown(cellData.source.path);
var res = true;
if (typeof this.controller.CONFIG.triggers["rowClick"] === "function") {
var d = this.controller.getRowsValues([rowIndex])[0].slice(
this.controller.dataController.getData().info.leftHeaderColumnsNumber
);
res = this.controller.CONFIG.triggers["rowClick"](rowIndex, d);
}
if (res !== false)
this.controller.tryDrillDown(cellData.source.path);

};

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

if (typeof this.controller.CONFIG.triggers["rowSelect"] === "function") {
this.controller.CONFIG.triggers["rowSelect"](this.controller.getSelectedRows());
var rows = this.controller.getSelectedRows();
this.controller.CONFIG.triggers["rowSelect"](
rows,
this.controller.getRowsValues(rows)
);
}

};
Expand Down

0 comments on commit 46e48f0

Please sign in to comment.