@@ -179,7 +179,26 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
179
179
* this.parentVirtDir.totalItemCount = data.Count;
180
180
* ```
181
181
*/
182
- public totalItemCount : number = null ;
182
+ public get totalItemCount ( ) {
183
+ return this . _totalItemCount ;
184
+ }
185
+
186
+ public set totalItemCount ( val ) {
187
+ if ( this . _totalItemCount !== val ) {
188
+ this . _totalItemCount = val ;
189
+ // update sizes in case total count changes.
190
+ const newSize = this . initSizesCache ( this . igxForOf ) ;
191
+ const sizeDiff = this . scrollComponent . size - newSize ;
192
+ this . scrollComponent . size = newSize ;
193
+ const lastChunkExceeded = this . state . startIndex + this . state . chunkSize > val ;
194
+ if ( lastChunkExceeded ) {
195
+ this . state . startIndex = val - this . state . chunkSize ;
196
+ }
197
+ this . _adjustScrollPositionAfterSizeChange ( sizeDiff ) ;
198
+ }
199
+ }
200
+
201
+ private _totalItemCount : number = null ;
183
202
184
203
/**
185
204
* An event that is emitted after a new chunk has been loaded.
@@ -320,7 +339,7 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
320
339
/**
321
340
* @hidden
322
341
*/
323
- protected get isRemote ( ) : boolean {
342
+ public get isRemote ( ) : boolean {
324
343
return this . totalItemCount !== null ;
325
344
}
326
345
@@ -1117,13 +1136,17 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
1117
1136
const newHeight = this . initSizesCache ( this . igxForOf ) ;
1118
1137
1119
1138
const diff = oldHeight - newHeight ;
1139
+ this . _adjustScrollPositionAfterSizeChange ( diff ) ;
1140
+ }
1120
1141
1142
+ private _adjustScrollPositionAfterSizeChange ( sizeDiff ) {
1121
1143
// if data has been changed while container is scrolled
1122
1144
// should update scroll top/left according to change so that same startIndex is in view
1123
- if ( Math . abs ( diff ) > 0 && this . scrollPosition > 0 ) {
1145
+ if ( Math . abs ( sizeDiff ) > 0 && this . scrollPosition > 0 ) {
1124
1146
this . recalcUpdateSizes ( ) ;
1125
1147
const offset = parseInt ( this . dc . instance . _viewContainer . element . nativeElement . style . top , 10 ) ;
1126
- this . scrollPosition = this . sizesCache [ this . state . startIndex ] - offset ;
1148
+ const newSize = this . sizesCache [ this . state . startIndex ] - offset ;
1149
+ this . scrollPosition = newSize === this . scrollPosition ? newSize + 1 : newSize ;
1127
1150
}
1128
1151
}
1129
1152
@@ -1525,7 +1548,7 @@ export class IgxGridForOfDirective<T> extends IgxForOfDirective<T> implements On
1525
1548
if ( changes && ! this . isRemote ) {
1526
1549
newHeight = this . handleCacheChanges ( changes ) ;
1527
1550
} else {
1528
- newHeight = this . initSizesCache ( this . igxForOf ) ;
1551
+ return ;
1529
1552
}
1530
1553
1531
1554
const diff = oldHeight - newHeight ;
0 commit comments