@@ -401,7 +401,7 @@ angular.module('ui.grid')
401
401
scrollLeft = ( this . getCanvasWidth ( ) - this . getViewportWidth ( ) ) * scrollPercentage ;
402
402
}
403
403
404
- this . adjustColumns ( scrollLeft , scrollPercentage ) ;
404
+ this . adjustColumns ( scrollLeft ) ;
405
405
406
406
this . prevScrollLeft = scrollLeft ;
407
407
this . prevScrollleftPercentage = scrollPercentage ;
@@ -458,25 +458,15 @@ angular.module('ui.grid')
458
458
self . prevRowScrollIndex = rowIndex ;
459
459
} ;
460
460
461
- GridRenderContainer . prototype . adjustColumns = function adjustColumns ( scrollLeft , scrollPercentage ) {
461
+ GridRenderContainer . prototype . adjustColumns = function adjustColumns ( scrollLeft ) {
462
462
var self = this ;
463
463
464
464
var minCols = self . minColumnsToRender ( ) ;
465
465
466
466
var columnCache = self . visibleColumnCache ;
467
467
var maxColumnIndex = columnCache . length - minCols ;
468
468
469
- // Calculate the scroll percentage according to the scrollLeft location, if no percentage was provided
470
- if ( ( typeof ( scrollPercentage ) === 'undefined' || scrollPercentage === null ) && scrollLeft ) {
471
- scrollPercentage = scrollLeft / self . getHorizontalScrollLength ( ) ;
472
- }
473
-
474
- var colIndex = Math . ceil ( Math . min ( maxColumnIndex , maxColumnIndex * scrollPercentage ) ) ;
475
-
476
- // Define a max row index that we can't scroll past
477
- if ( colIndex > maxColumnIndex ) {
478
- colIndex = maxColumnIndex ;
479
- }
469
+ var colIndex = Math . min ( maxColumnIndex , self . getLeftIndex ( scrollLeft ) ) ;
480
470
481
471
var newRange = [ ] ;
482
472
if ( columnCache . length > self . grid . options . columnVirtualizationThreshold && self . getCanvasWidth ( ) > self . getViewportWidth ( ) ) {
@@ -496,6 +486,20 @@ angular.module('ui.grid')
496
486
self . prevColumnScrollIndex = colIndex ;
497
487
} ;
498
488
489
+ GridRenderContainer . prototype . getLeftIndex = function getLeftIndex ( scrollLeft ) {
490
+ var wholeLeftWidth = 0 ;
491
+ var index = 0
492
+ for ( index ; index < this . visibleColumnCache . length ; index ++ ) {
493
+ if ( this . visibleColumnCache [ index ] && this . visibleColumnCache [ index ] . visible ) {
494
+ //accumulate the whole width of columns on the left side, till the point of visibility is surpassed, this is our wanted index
495
+ wholeLeftWidth += this . visibleColumnCache [ index ] . drawnWidth ;
496
+ if ( wholeLeftWidth >= scrollLeft )
497
+ break ;
498
+ }
499
+ }
500
+ return index ;
501
+ }
502
+
499
503
// Method for updating the visible rows
500
504
GridRenderContainer . prototype . updateViewableRowRange = function updateViewableRowRange ( renderedRange ) {
501
505
// Slice out the range of rows from the data
0 commit comments