Skip to content

Commit 086307b

Browse files
committed
Fixed scrolling behavior with TOI
1 parent 938bf3c commit 086307b

File tree

1 file changed

+44
-27
lines changed

1 file changed

+44
-27
lines changed

platform/features/table/src/controllers/MCTTableController.js

+44-27
Original file line numberDiff line numberDiff line change
@@ -200,19 +200,52 @@ define(
200200
this.$scope.$digest();
201201
};
202202

203+
/**
204+
* @private
205+
*/
206+
MCTTableController.prototype.firstVisible = function () {
207+
var target = this.scrollable[0],
208+
topScroll = target.scrollTop,
209+
firstVisible;
210+
211+
if (topScroll < this.$scope.headerHeight) {
212+
firstVisible = 0;
213+
} else {
214+
firstVisible = Math.floor(
215+
(topScroll - this.$scope.headerHeight) /
216+
this.$scope.rowHeight
217+
);
218+
}
219+
220+
return firstVisible;
221+
};
222+
223+
/**
224+
* @private
225+
*/
226+
MCTTableController.prototype.lastVisible = function () {
227+
var target = this.scrollable[0],
228+
topScroll = target.scrollTop,
229+
bottomScroll = topScroll + target.offsetHeight,
230+
lastVisible;
231+
232+
lastVisible = Math.ceil(
233+
(bottomScroll - this.$scope.headerHeight) /
234+
this.$scope.rowHeight
235+
);
236+
return lastVisible;
237+
};
238+
203239
/**
204240
* Sets visible rows based on array
205241
* content and current scroll state.
206242
*/
207243
MCTTableController.prototype.setVisibleRows = function () {
208244
var self = this,
209-
target = this.scrollable[0],
210-
topScroll = target.scrollTop,
211-
bottomScroll = topScroll + target.offsetHeight,
212-
firstVisible,
213-
lastVisible,
214245
totalVisible,
215246
numberOffscreen,
247+
firstVisible,
248+
lastVisible,
216249
start,
217250
end;
218251

@@ -221,21 +254,8 @@ define(
221254
start = 0;
222255
end = this.$scope.displayRows.length;
223256
} else {
224-
//rows has exceeded display maximum, so may be necessary to
225-
// scroll
226-
if (topScroll < this.$scope.headerHeight) {
227-
firstVisible = 0;
228-
} else {
229-
firstVisible = Math.floor(
230-
(topScroll - this.$scope.headerHeight) /
231-
this.$scope.rowHeight
232-
);
233-
}
234-
lastVisible = Math.ceil(
235-
(bottomScroll - this.$scope.headerHeight) /
236-
this.$scope.rowHeight
237-
);
238-
257+
firstVisible = this.firstVisible();
258+
lastVisible = this.lastVisible();
239259
totalVisible = lastVisible - firstVisible;
240260
numberOffscreen = this.maxDisplayRows - totalVisible;
241261
start = firstVisible - Math.floor(numberOffscreen / 2);
@@ -337,7 +357,6 @@ define(
337357
if (max < min) {
338358
return min; // Element is not in array, min gives direction
339359
}
340-
341360
switch (this.sortComparator(searchElement,
342361
searchArray[sampleAt][this.$scope.sortColumn].text)) {
343362
case -1:
@@ -565,9 +584,7 @@ define(
565584

566585
MCTTableController.prototype.scrollToRow = function (displayRowIndex) {
567586

568-
var visible = this.$scope.visibleRows.reduce(function (exists, row) {
569-
return exists || (row.rowIndex === displayRowIndex)
570-
}, false);
587+
var visible = displayRowIndex > this.firstVisible() && displayRowIndex < this.lastVisible();
571588

572589
if (!visible) {
573590
var scrollTop = displayRowIndex * this.$scope.rowHeight
@@ -587,10 +604,10 @@ define(
587604
if (this.$scope.timeColumns.indexOf(this.$scope.sortColumn) !== -1
588605
&& newTOI
589606
&& this.$scope.displayRows.length > 0) {
590-
var formattedTOI = this.toiFormatter.format(newTOI);
591-
var rowsLength = this.$scope.displayRows.length;
607+
var formattedTOI = this.toiFormatter.format(newTOI);;
592608
// searchElement, min, max
593-
this.$scope.toiRowIndex = this.binarySearch(this.$scope.displayRows, formattedTOI, 0, rowsLength);
609+
this.$scope.toiRowIndex = this.binarySearch(this.$scope.displayRows,
610+
formattedTOI, 0, this.$scope.displayRows.length - 1);
594611
this.scrollToRow(this.$scope.toiRowIndex);
595612
}
596613
};

0 commit comments

Comments
 (0)