@@ -200,19 +200,52 @@ define(
200
200
this . $scope . $digest ( ) ;
201
201
} ;
202
202
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
+
203
239
/**
204
240
* Sets visible rows based on array
205
241
* content and current scroll state.
206
242
*/
207
243
MCTTableController . prototype . setVisibleRows = function ( ) {
208
244
var self = this ,
209
- target = this . scrollable [ 0 ] ,
210
- topScroll = target . scrollTop ,
211
- bottomScroll = topScroll + target . offsetHeight ,
212
- firstVisible ,
213
- lastVisible ,
214
245
totalVisible ,
215
246
numberOffscreen ,
247
+ firstVisible ,
248
+ lastVisible ,
216
249
start ,
217
250
end ;
218
251
@@ -221,21 +254,8 @@ define(
221
254
start = 0 ;
222
255
end = this . $scope . displayRows . length ;
223
256
} 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 ( ) ;
239
259
totalVisible = lastVisible - firstVisible ;
240
260
numberOffscreen = this . maxDisplayRows - totalVisible ;
241
261
start = firstVisible - Math . floor ( numberOffscreen / 2 ) ;
@@ -337,7 +357,6 @@ define(
337
357
if ( max < min ) {
338
358
return min ; // Element is not in array, min gives direction
339
359
}
340
-
341
360
switch ( this . sortComparator ( searchElement ,
342
361
searchArray [ sampleAt ] [ this . $scope . sortColumn ] . text ) ) {
343
362
case - 1 :
@@ -565,9 +584,7 @@ define(
565
584
566
585
MCTTableController . prototype . scrollToRow = function ( displayRowIndex ) {
567
586
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 ( ) ;
571
588
572
589
if ( ! visible ) {
573
590
var scrollTop = displayRowIndex * this . $scope . rowHeight
@@ -587,10 +604,10 @@ define(
587
604
if ( this . $scope . timeColumns . indexOf ( this . $scope . sortColumn ) !== - 1
588
605
&& newTOI
589
606
&& 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 ) ; ;
592
608
// 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 ) ;
594
611
this . scrollToRow ( this . $scope . toiRowIndex ) ;
595
612
}
596
613
} ;
0 commit comments