Skip to content

Commit f7feb7d

Browse files
restoring scroll positions after sort
1 parent d34e143 commit f7feb7d

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

source/js/PivotView.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ var PivotView = function (controller, container) {
3333
*/
3434
this.pagination = null;
3535

36+
/**
37+
* Saved scroll positions.
38+
* @type {{x: number, y: number}}
39+
*/
40+
this.savedScroll = {
41+
x: 0,
42+
y: 0
43+
};
44+
3645
this.PAGINATION_BLOCK_HEIGHT = 20;
3746
this.ANIMATION_TIMEOUT = 500;
3847

@@ -168,6 +177,34 @@ PivotView.prototype.popTable = function () {
168177

169178
};
170179

180+
PivotView.prototype.saveScrollPosition = function () {
181+
182+
var els;
183+
184+
if (
185+
this.elements.tableContainer
186+
&& (els = this.elements.tableContainer.getElementsByClassName("lpt-tableBlock"))
187+
) {
188+
this.savedScroll.x = els[0].scrollLeft;
189+
this.savedScroll.y = els[0].scrollTop;
190+
}
191+
192+
};
193+
194+
PivotView.prototype.restoreScrollPosition = function () {
195+
196+
var els;
197+
198+
if (
199+
this.elements.tableContainer
200+
&& (els = this.elements.tableContainer.getElementsByClassName("lpt-tableBlock"))
201+
) {
202+
els[0].scrollLeft = this.savedScroll.x;
203+
els[0].scrollTop = this.savedScroll.y;
204+
}
205+
206+
};
207+
171208
/**
172209
* Data change handler.
173210
*
@@ -193,7 +230,9 @@ PivotView.prototype.dataChanged = function (data) {
193230

194231
PivotView.prototype._columnClickHandler = function (columnIndex) {
195232

233+
this.saveScrollPosition();
196234
this.controller.dataController.sortByColumn(columnIndex);
235+
this.restoreScrollPosition();
197236

198237
};
199238

0 commit comments

Comments
 (0)