Skip to content

Commit 6ce8a48

Browse files
added row number option, headers are non-selectable now
1 parent bce2b43 commit 6ce8a48

File tree

7 files changed

+58
-4
lines changed

7 files changed

+58
-4
lines changed

example/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
//, columnResizing: true // make columns resizable (default: true)
132132
//, enableSearch: false // enables search panel in listing
133133
//, stretchColumns: true // stretch columns to fill all available width (default: true)
134+
//, showRowNumbers: true // show the row number in first column
134135
};
135136

136137
var e;

export/LightPivotTable-DeepSeePortlet.xml

Lines changed: 8 additions & 2 deletions
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,75399.850452</TimeChanged>
14+
<TimeChanged>63699,80103.61817</TimeChanged>
1515
<TimeCreated>63515,61322.546099</TimeCreated>
1616

1717
<Parameter name="INCLUDEFILES">
@@ -58,6 +58,10 @@
5858
<Type>%Boolean</Type>
5959
</Property>
6060

61+
<Property name="ShowRowNumbers">
62+
<Type>%Boolean</Type>
63+
</Property>
64+
6165
<Method name="%OnGetPortletName">
6266
<ClassMethod>1</ClassMethod>
6367
<ReturnType>%String</ReturnType>
@@ -89,6 +93,7 @@
8993
set pInfo($I(pInfo)) = $LB("ColumnResizing", 1, "%Boolean", "Column resizing", "Allow resizing columns with cursor")
9094
set pInfo($I(pInfo)) = $LB("EnableSearch", 1, "%Boolean", "Enable listing search", "Show search tools in listing mode")
9195
set pInfo($I(pInfo)) = $LB("StretchColumns", 0, "%Boolean", "Stretch columns", "Stretch columns to fill all available width")
96+
set pInfo($I(pInfo)) = $LB("ShowRowNumbers", 0, "%Boolean", "Show row nums", "Show row number in listing")
9297
9398
quit $$$OK
9499
]]></Implementation>
@@ -272,6 +277,7 @@
272277
setup["columnResizing"] = !!parseInt(container.getAttribute("columnResizing"));
273278
setup["enableSearch"] = !!parseInt(container.getAttribute("enableSearch"));
274279
setup["stretchColumns"] = !!parseInt(container.getAttribute("stretchColumns"));
280+
setup["showRowNumbers"] = !!parseInt(container.getAttribute("showRowNumbers"));
275281
if (parseInt(container.getAttribute("pagination"))) {
276282
setup["pagination"] = parseInt(container.getAttribute("pagination"))
277283
}
@@ -408,7 +414,7 @@
408414
}
409415
410416
&html<
411-
<div stretchColumns="#(..StretchColumns)#" namespace="#($NAMESPACE)#" enableSearch="#(..EnableSearch)#" columnResizing="#(..ColumnResizing)#" session="#(%session.CSPSessionCookie)#" maxHeaderWidth="#(..MaxHeaderWidth)#" listingColumnMinWidth="#(..ListingColumnMinWidth)#" fixTotals="#(..FixTotals)#" pagination="#(..Pagination)#" export-csv="#(..ExportCSV)#" data-source="#(..DataSourceApp)#" show-summary="#(..ShowSummary)#" class="lpt-container" style="position: absolute; left: 0; bottom: 0; width: 100%; height: 100%;">
417+
<div stretchColumns="#(..StretchColumns)#" showRowNumbers="#(..ShowRowNumbers)#" namespace="#($NAMESPACE)#" enableSearch="#(..EnableSearch)#" columnResizing="#(..ColumnResizing)#" session="#(%session.CSPSessionCookie)#" maxHeaderWidth="#(..MaxHeaderWidth)#" listingColumnMinWidth="#(..ListingColumnMinWidth)#" fixTotals="#(..FixTotals)#" pagination="#(..Pagination)#" export-csv="#(..ExportCSV)#" data-source="#(..DataSourceApp)#" show-summary="#(..ShowSummary)#" class="lpt-container" style="position: absolute; left: 0; bottom: 0; width: 100%; height: 100%;">
412418
413419
</div>
414420
>

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.1",
4+
"version": "1.0.3",
55
"description": "A lightweight pivot table for MDX2JSON source for InterSystems Cache",
66
"main": "test/testServer.js",
77
"repository": {

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ var setup = { // Object that contain settings. Properties in brackets can be mis
6969
[ , columnResizing: true ] // make columns resizable (default: true)
7070
[ , columnResizeAnimation: false ] // animate column when resizing
7171
[ , enableSearch: true ] // enables search panel in listing (default: true)
72+
[ , showRowNumbers: true ] // show the row number in first column
7273
},
7374
lp = new LightPivotTable(setup);
7475

source/css/LightPivot.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@
7171
border-bottom: 1px solid rgb(208, 208, 208);
7272
}
7373

74+
.lpt th {
75+
-webkit-user-select: none;
76+
-moz-user-select: none;
77+
-ms-user-select: none;
78+
user-select: none;
79+
}
80+
7481
.lpt th, .lpt .lpt-headerValue {
7582
background: #F0F0F0;
7683
}

source/js/DataController.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ DataController.prototype.setData = function (data) {
100100
this.resetDimensionProps();
101101
this.resetConditionalFormatting();
102102
this.resetRawData();
103+
this.modifyRawData(data);
103104

104105
if (data.info.mdxType === "drillthrough") {
105106
this.setDrillThroughHandler(function (params) {
@@ -564,6 +565,7 @@ DataController.prototype.sortByColumn = function (columnIndex) {
564565

565566
if (order === 0) {
566567
data.rawData = data._rawDataOrigin;
568+
this.modifyRawData(data);
567569
this._trigger();
568570
return;
569571
}
@@ -586,6 +588,8 @@ DataController.prototype.sortByColumn = function (columnIndex) {
586588
[data.info.leftHeaderColumnsNumber + columnIndex]
587589
.className = order === 0 ? "" : order === 1 ? "lpt-sortDesc" : "lpt-sortAsc";
588590

591+
this.modifyRawData(data);
592+
589593
this._trigger();
590594

591595
};
@@ -627,6 +631,41 @@ DataController.prototype.filterByValue = function (valuePart, columnIndex) {
627631
: []
628632
);
629633

634+
this.modifyRawData(data);
635+
630636
this._trigger();
631637

638+
};
639+
640+
/**
641+
* Modifies data if such settings are present.
642+
*/
643+
DataController.prototype.modifyRawData = function (data) {
644+
645+
// modify data.rawData and original properties (such as width and height) if needed.
646+
647+
var i = -1;
648+
649+
if (this.controller.CONFIG.showRowNumbers && !data.info.leftHeaderColumnsNumber) { // listing
650+
if (data.rawData[0] && data.rawData[0][0].special) { // just update indexes
651+
data.rawData.forEach(function (row) {
652+
row[0].value = ++i === 0 ? "#" : i;
653+
row[0].isCaption = i === 0;
654+
});
655+
} else { // re-create indexes
656+
data.rawData.forEach(function (row) {
657+
row.unshift({
658+
value: ++i === 0 ? "#" : i,
659+
isCaption: i === 0,
660+
special: true,
661+
noClick: true
662+
});
663+
});
664+
if (data.columnProps instanceof Array) {
665+
data.columnProps.unshift({});
666+
}
667+
data.info.colCount++;
668+
}
669+
}
670+
632671
};

source/js/PivotView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ PivotView.prototype.renderRawData = function (data) {
924924
if (!vertical && y === yTo - 1 - ATTACH_TOTALS && !th["_hasSortingListener"]) {
925925
th["_hasSortingListener"] = false; // why false?
926926
//console.log("Click bind to", th);
927-
th.addEventListener(CLICK_EVENT, (function (i) {
927+
if (!rawData[y][x].noClick) th.addEventListener(CLICK_EVENT, (function (i) {
928928
return function () {
929929
//if (th._CANCEL_CLICK_EVENT) return;
930930
_._columnClickHandler.call(_, i);

0 commit comments

Comments
 (0)