@@ -1413,14 +1413,19 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
14131413 }
14141414
14151415
1416- private _adjustScrollPositionAfterSizeChange ( sizeDiff ) {
1416+ protected _adjustScrollPositionAfterSizeChange ( sizeDiff ) {
14171417 // if data has been changed while container is scrolled
14181418 // should update scroll top/left according to change so that same startIndex is in view
14191419 if ( Math . abs ( sizeDiff ) > 0 && this . scrollPosition > 0 ) {
14201420 this . recalcUpdateSizes ( ) ;
1421- const offset = parseInt ( this . dc . instance . _viewContainer . element . nativeElement . style . top , 10 ) ;
1421+ const offset = this . igxForScrollOrientation === 'horizontal' ?
1422+ parseInt ( this . dc . instance . _viewContainer . element . nativeElement . style . left , 10 ) :
1423+ parseInt ( this . dc . instance . _viewContainer . element . nativeElement . style . top , 10 ) ;
14221424 const newSize = this . sizesCache [ this . state . startIndex ] - offset ;
1423- this . scrollPosition = newSize === this . scrollPosition ? newSize + 1 : newSize ;
1425+ this . scrollPosition = newSize ;
1426+ if ( this . scrollPosition !== newSize ) {
1427+ this . scrollComponent . scrollAmount = newSize ;
1428+ }
14241429 }
14251430 }
14261431
@@ -1575,8 +1580,11 @@ export class IgxGridForOfDirective<T> extends IgxForOfDirective<T> implements On
15751580 }
15761581 this . syncService . setMaster ( this ) ;
15771582 this . igxForContainerSize = args . containerSize ;
1578- this . _updateSizeCache ( changes ) ;
1583+ const sizeDiff = this . _updateSizeCache ( changes ) ;
15791584 this . _applyChanges ( ) ;
1585+ if ( sizeDiff ) {
1586+ this . _adjustScrollPositionAfterSizeChange ( sizeDiff ) ;
1587+ }
15801588 this . _updateScrollOffset ( ) ;
15811589 this . dataChanged . emit ( ) ;
15821590 }
@@ -1652,8 +1660,10 @@ export class IgxGridForOfDirective<T> extends IgxForOfDirective<T> implements On
16521660
16531661 protected _updateSizeCache ( changes : IterableChanges < T > = null ) {
16541662 if ( this . igxForScrollOrientation === 'horizontal' ) {
1655- this . initSizesCache ( this . igxForOf ) ;
1656- return ;
1663+ const oldSize = this . sizesCache [ this . sizesCache . length - 1 ] ;
1664+ const newSize = this . initSizesCache ( this . igxForOf ) ;
1665+ const diff = oldSize - newSize ;
1666+ return diff ;
16571667 }
16581668
16591669 const oldHeight = this . heightCache . length > 0 ? this . heightCache . reduce ( ( acc , val ) => acc + val ) : 0 ;
@@ -1681,6 +1691,7 @@ export class IgxGridForOfDirective<T> extends IgxForOfDirective<T> implements On
16811691 }
16821692 } ) ;
16831693 }
1694+ return diff ;
16841695 }
16851696
16861697 protected handleCacheChanges ( changes : IterableChanges < T > ) {
0 commit comments