Skip to content

Commit 726b133

Browse files
selectable rows in listing feature
1 parent 6ce8a48 commit 726b133

File tree

6 files changed

+73
-6
lines changed

6 files changed

+73
-6
lines changed

example/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
//, back: function ({Object { level: {number} }}) {}
115115
// if cellDrillThrough callback returns boolean false, DrillThrough won't be performed.
116116
//, cellDrillThrough: function ({Object { event: {event}, filters: {string[]} }}) {}
117+
//, rowSelect: function (rs) { console.log("Rows: ", rs); }
117118
}
118119
, pagination: 30 // Maximum rows number on one page (default: 200, turn off: 0)
119120
//, hideButtons: true // hides "back" and "drillThrough" buttons
@@ -132,6 +133,7 @@
132133
//, enableSearch: false // enables search panel in listing
133134
//, stretchColumns: true // stretch columns to fill all available width (default: true)
134135
//, showRowNumbers: true // show the row number in first column
136+
//, enableListingSelect: true // enable selection in listing
135137
};
136138

137139
var e;

export/LightPivotTable-DeepSeePortlet.xml

Lines changed: 8 additions & 1 deletion
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>63699,80103.61817</TimeChanged>
14+
<TimeChanged>63700,68026.762239</TimeChanged>
1515
<TimeCreated>63515,61322.546099</TimeCreated>
1616

1717
<Parameter name="INCLUDEFILES">
@@ -263,6 +263,13 @@
263263
basicMDX: info["mdx"],
264264
MDX2JSONSource: source,
265265
namespace: container.getAttribute("namespace")
266+
},
267+
triggers: {
268+
rowSelect: function (selectedRows) {
269+
var ss = [];
270+
selectedRows.forEach(function (e) { ss.push(e + ",," + (e + 1) + ",,,1") });
271+
controller.setProperty("selectedRange", ss.join("\n"));
272+
}
266273
}
267274
}
268275
if (controller.contextFilterSpec) {

package.json

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

readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ var setup = { // Object that contain settings. Properties in brackets can be mis
5252
// if cellDrillThrough callback returns boolean false, DrillThrough won't be performed.
5353
, cellDrillThrough: function ({Object { event: {event}, filters: {string[]}, cellData: {object} }}) {}
5454
, responseHandler: function ({Object {url: {string}, status: {number}}}) {}
55+
, rowSelect: function ({Array}) {}
5556
} ]
5657
[ , pagination: 30 ] // Maximum rows number on one page (default: 200, turn off: 0)
5758
[ , hideButtons: true ] // hides "back" and "drillThrough" buttons
@@ -70,6 +71,7 @@ var setup = { // Object that contain settings. Properties in brackets can be mis
7071
[ , columnResizeAnimation: false ] // animate column when resizing
7172
[ , enableSearch: true ] // enables search panel in listing (default: true)
7273
[ , showRowNumbers: true ] // show the row number in first column
74+
[ , enableListingSelect: true ] // enable listing selection, true by default
7375
},
7476
lp = new LightPivotTable(setup);
7577

@@ -86,6 +88,7 @@ lp.refresh(); // refresh pivot contents
8688
lp.updateSizes(); // recalculate pivot sizes
8789
lp.changeBasicMDX("..."); // change mdx for LPT
8890
lp.getActualMDX(); // returns currently displayed MDX
91+
lp.getSelectedRows(); // returns array with selected rows indexes. First row have index 1.
8992
```
9093

9194
#### Caché DeepSee

source/js/LightPivotTable.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,21 @@ LightPivotTable.prototype.getActualMDX = function () {
105105

106106
};
107107

108+
/**
109+
* Return array with selected rows indexes.
110+
*/
111+
LightPivotTable.prototype.getSelectedRows = function () {
112+
113+
var arr = [], rows = this.pivotView.selectedRows, i;
114+
115+
for (i in rows) {
116+
if (rows[i]) arr.push(+i);
117+
}
118+
119+
return arr;
120+
121+
};
122+
108123
/**
109124
* Performs resizing.
110125
*/
@@ -299,6 +314,7 @@ LightPivotTable.prototype.normalizeConfiguration = function (config) {
299314
if (typeof config["pagination"] === "undefined") config.pagination = 200;
300315
if (typeof config["enableSearch"] === "undefined") config.enableSearch = true;
301316
if (typeof config["stretchColumns"] === "undefined") config.stretchColumns = true;
317+
if (typeof config["enableListingSelect"] === "undefined") config.enableListingSelect = true;
302318
if (!config["triggers"]) config.triggers = {};
303319
if (!config["dataSource"]) config.dataSource = {};
304320
};

source/js/PivotView.js

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var PivotView = function (controller, container) {
99
"instance \"container\" into pivot table configuration.");
1010

1111
this.tablesStack = [];
12+
this.selectedRows = {}; // rowNumber: 1
1213

1314
numeral.call(this);
1415

@@ -150,6 +151,7 @@ PivotView.prototype.pushTable = function (opts) {
150151
if (this.tablesStack.length) {
151152
this.tablesStack[this.tablesStack.length - 1].FIXED_COLUMN_SIZES = this.FIXED_COLUMN_SIZES;
152153
this.tablesStack[this.tablesStack.length - 1].savedSearch = this.savedSearch;
154+
this.tablesStack[this.tablesStack.length - 1].selectedRows = this.selectedRows;
153155
this.savedSearch = { restore: false, value: "", columnIndex: 0 };
154156
tableElement.style.left = "100%";
155157
}
@@ -166,6 +168,7 @@ PivotView.prototype.pushTable = function (opts) {
166168
});
167169

168170
this.FIXED_COLUMN_SIZES = [];
171+
this.selectedRows = {};
169172
this.elements.base.appendChild(tableElement);
170173
this.elements.tableContainer = tableElement;
171174
this.pagination = pg;
@@ -189,6 +192,7 @@ PivotView.prototype.popTable = function () {
189192
this.pagination = (currentTable = this.tablesStack[this.tablesStack.length - 1]).pagination;
190193
if (currentTable.FIXED_COLUMN_SIZES) this.FIXED_COLUMN_SIZES = currentTable.FIXED_COLUMN_SIZES;
191194
if (currentTable.savedSearch) this.savedSearch = currentTable.savedSearch;
195+
if (currentTable.selectedRows) this.selectedRows = currentTable.selectedRows;
192196

193197
setTimeout(function () {
194198
garbage.element.parentNode.removeChild(garbage.element);
@@ -237,9 +241,7 @@ PivotView.prototype.dataChanged = function (data) {
237241

238242
if (this.controller.CONFIG.pagination) this.pagination.on = true;
239243
this.pagination.rows = this.controller.CONFIG.pagination || Infinity;
240-
//? this.controller.CONFIG.pagination
241-
//+ data.info.topHeaderRowsNumber + (data.info.SUMMARY_SHOWN ? 1 : 0)
242-
//: Infinity;
244+
this.selectedRows = {};
243245
this.pagination.page = 0;
244246
this.pagination.pages = Math.ceil(dataRows / this.pagination.rows);
245247
if (this.pagination.pages < 2) this.pagination.on = false;
@@ -505,6 +507,23 @@ PivotView.prototype.colorNameToRGB = function (name) {
505507
}
506508
};
507509

510+
/**
511+
* @param {boolean} select - select or not.
512+
* @param {number} rowNumber - row number start from 0.
513+
*/
514+
PivotView.prototype.selectRow = function (select, rowNumber) {
515+
516+
if (select)
517+
this.selectedRows[rowNumber] = 1;
518+
else
519+
delete this.selectedRows[rowNumber];
520+
521+
if (typeof this.controller.CONFIG.triggers["rowSelect"] === "function") {
522+
this.controller.CONFIG.triggers["rowSelect"](this.controller.getSelectedRows());
523+
}
524+
525+
};
526+
508527
/**
509528
* Size updater for LPT.
510529
* Do not affect scroll positions in this function.
@@ -728,6 +747,7 @@ PivotView.prototype.renderRawData = function (data) {
728747
COLUMN_RESIZE_ON = !!this.controller.CONFIG.columnResizing,
729748
LISTING = info.leftHeaderColumnsNumber === 0,
730749
SEARCH_ENABLED = LISTING && this.controller.CONFIG["enableSearch"],
750+
LISTING_SELECT_ENABLED = this.controller.CONFIG["enableListingSelect"],
731751
RESIZE_ANIMATION = !!this.controller.CONFIG["columnResizeAnimation"],
732752

733753
container = this.elements.tableContainer,
@@ -856,7 +876,26 @@ PivotView.prototype.renderRawData = function (data) {
856876
var renderHeader = function (xFrom, xTo, yFrom, yTo, targetElement) {
857877

858878
var vertical = targetElement === LHTHead,
859-
rendered, separatelyGrouped, tr, th, div;
879+
rendered, separatelyGrouped, tr, th, div, checkbox;
880+
881+
if (xFrom === xTo && LISTING_SELECT_ENABLED) { // listing
882+
for (y = yFrom; y < yTo; y++) {
883+
tr = document.createElement("tr");
884+
th = document.createElement("td");
885+
checkbox = document.createElement("input");
886+
checkbox.setAttribute("type", "checkbox");
887+
checkbox.checked = !!_.selectedRows[y];
888+
th.setAttribute("style", "padding: 0 !important;");
889+
checkbox.addEventListener("change", (function (y) { return function (e) {
890+
_.selectRow.call(_, (e.srcElement || e.target).checked, y);
891+
}})(y));
892+
th.appendChild(checkbox);
893+
tr.appendChild(th);
894+
primaryRows.push(th);
895+
targetElement.appendChild(tr);
896+
}
897+
return;
898+
}
860899

861900
for (y = yFrom; y < yTo; y++) {
862901
for (x = xFrom; x < xTo; x++) {

0 commit comments

Comments
 (0)