Skip to content

Commit 25a2f68

Browse files
authored
Merge pull request #7318 from IgniteUI/mkirova/fix-9.0.x-7234
fix(virtualization): Use virtual scroll top which takes virtual heig
2 parents 4ee8f74 + e30083b commit 25a2f68

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

projects/igniteui-angular/src/lib/combo/combo.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,8 @@ describe('igxCombo', () => {
732732
scrollIndex += 10;
733733
if (scrollIndex < combo.data.length) {
734734
combo.virtualScrollContainer.scrollTo(scrollIndex);
735-
combo.virtualScrollContainer.onChunkLoad.pipe(take(1)).subscribe(() => {
735+
combo.virtualScrollContainer.onChunkLoad.pipe(take(1)).subscribe(async() => {
736+
await wait(30);
736737
checkGroupedItemsClass();
737738
});
738739
} else {

projects/igniteui-angular/src/lib/directives/for-of/for_of.directive.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -731,13 +731,8 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
731731
if (!parseInt(this.scrollComponent.nativeElement.style.height, 10)) {
732732
return;
733733
}
734-
735-
const containerSize = parseInt(this.igxForContainerSize, 10);
736-
const maxRealScrollTop = event.target.children[0].scrollHeight - containerSize;
737-
const realPercentScrolled = maxRealScrollTop !== 0 ? event.target.scrollTop / maxRealScrollTop : 0;
738734
if (!this._bScrollInternal) {
739-
const maxVirtScrollTop = this._virtHeight - containerSize;
740-
this._virtScrollTop = realPercentScrolled * maxVirtScrollTop;
735+
this._calcVirtualScrollTop(event.target.scrollTop);
741736
} else {
742737
this._bScrollInternal = false;
743738
}
@@ -1306,11 +1301,25 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
13061301
}
13071302
private _updateVScrollOffset() {
13081303
let scrollOffset = 0;
1304+
let currentScrollTop = this.scrollPosition;
1305+
if (this._virtHeightRatio !== 1) {
1306+
this._calcVirtualScrollTop(this.scrollPosition);
1307+
currentScrollTop = this._virtScrollTop;
1308+
}
13091309
const vScroll = this.scrollComponent.nativeElement;
13101310
scrollOffset = vScroll && this.scrollComponent.size ?
1311-
this.scrollPosition - this.sizesCache[this.state.startIndex] : 0;
1311+
currentScrollTop - this.sizesCache[this.state.startIndex] : 0;
13121312
this.dc.instance._viewContainer.element.nativeElement.style.top = -(scrollOffset) + 'px';
13131313
}
1314+
1315+
protected _calcVirtualScrollTop(scrollTop: number) {
1316+
const containerSize = parseInt(this.igxForContainerSize, 10);
1317+
const maxRealScrollTop = this.scrollComponent.size - containerSize;
1318+
const realPercentScrolled = maxRealScrollTop !== 0 ? scrollTop / maxRealScrollTop : 0;
1319+
const maxVirtScrollTop = this._virtHeight - containerSize;
1320+
this._virtScrollTop = realPercentScrolled * maxVirtScrollTop;
1321+
}
1322+
13141323
private _updateHScrollOffset() {
13151324
let scrollOffset = 0;
13161325
scrollOffset = this.scrollComponent.nativeElement &&
@@ -1581,13 +1590,8 @@ export class IgxGridForOfDirective<T> extends IgxForOfDirective<T> implements On
15811590
if (!parseInt(this.scrollComponent.nativeElement.style.height, 10)) {
15821591
return;
15831592
}
1584-
1585-
const containerSize = parseInt(this.igxForContainerSize, 10);
1586-
const maxRealScrollTop = event.target.children[0].scrollHeight - containerSize;
1587-
const realPercentScrolled = maxRealScrollTop !== 0 ? event.target.scrollTop / maxRealScrollTop : 0;
15881593
if (!this._bScrollInternal) {
1589-
const maxVirtScrollTop = this._virtHeight - containerSize;
1590-
this._virtScrollTop = realPercentScrolled * maxVirtScrollTop;
1594+
this._calcVirtualScrollTop(event.target.scrollTop);
15911595
} else {
15921596
this._bScrollInternal = false;
15931597
}

0 commit comments

Comments
 (0)