Skip to content

Commit 58e6489

Browse files
authored
fix(igxGrid): Fix offset when using virtual scrollbar with ratio. (#16346)
1 parent 4906f49 commit 58e6489

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

projects/igniteui-angular/core/src/data-operations/merge-strategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class DefaultMergeStrategy implements IGridMergeStrategy {
7474
index++;
7575
continue;
7676
}
77-
const recToUpdateData = recData ?? { recordRef: grid.isGhostRecord(rec) ? rec.recordRef : rec, cellMergeMeta: new Map<string, IMergeByResult>(), ghostRecord: rec.ghostRecord };
77+
const recToUpdateData = recData ?? { recordRef: grid.isGhostRecord(rec) ? rec.recordRef : rec, cellMergeMeta: new Map<string, IMergeByResult>(), ghostRecord: rec.ghostRecord, index: index };
7878
recToUpdateData.cellMergeMeta.set(field, { rowSpan: 1, childRecords: [] });
7979
if (prev && comparer.call(this, prev.recordRef, recToUpdateData.recordRef, field, isDate, isTime) && prev.ghostRecord === recToUpdateData.ghostRecord) {
8080
const root = prev.cellMergeMeta.get(field)?.root ?? prev;

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,11 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
275275
protected _differ: IterableDiffer<T> | null = null;
276276
protected _trackByFn: TrackByFunction<T>;
277277
protected individualSizeCache: number[] = [];
278+
/**
279+
* @hidden
280+
*/
278281
/** Internal track for scroll top that is being virtualized */
279-
protected _virtScrollPosition = 0;
282+
public _virtScrollPosition = 0;
280283
/** If the next onScroll event is triggered due to internal setting of scrollTop */
281284
protected _bScrollInternal = false;
282285
// End properties related to virtual height handling
@@ -901,7 +904,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
901904
const maxVirtScrollTop = this._virtSize - containerSize;
902905
this._bScrollInternal = true;
903906
this._virtScrollPosition = maxVirtScrollTop;
904-
this.scrollPosition = maxVirtScrollTop;
907+
this.scrollPosition = maxVirtScrollTop / this._virtRatio;
905908
return;
906909
}
907910
if (this._adjustToIndex) {
@@ -1529,11 +1532,12 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
15291532
let currentScroll = this.scrollPosition;
15301533
if (this._virtRatio !== 1) {
15311534
this._calcVirtualScrollPosition(this.scrollPosition);
1532-
currentScroll = this._virtScrollPosition;
1535+
scrollOffset = this.fixedUpdateAllElements(this._virtScrollPosition);
1536+
} else {
1537+
const scroll = this.scrollComponent.nativeElement;
1538+
scrollOffset = scroll && this.scrollComponent.size ?
1539+
currentScroll - this.sizesCache[this.state.startIndex] : 0;
15331540
}
1534-
const scroll = this.scrollComponent.nativeElement;
1535-
scrollOffset = scroll && this.scrollComponent.size ?
1536-
currentScroll - this.sizesCache[this.state.startIndex] : 0;
15371541
const dir = this.igxForScrollOrientation === 'horizontal' ? 'left' : 'transform';
15381542
this.dc.instance._viewContainer.element.nativeElement.style[dir] = this.igxForScrollOrientation === 'horizontal' ?
15391543
-(scrollOffset) + 'px' :

projects/igniteui-angular/grids/grid/src/grid-base.directive.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3666,7 +3666,7 @@ export abstract class IgxGridBaseDirective implements GridType,
36663666

36673667
protected getMergeCellOffset(rowData) {
36683668
const index = rowData.dataIndex;
3669-
let offset = this.verticalScrollContainer.scrollPosition - this.verticalScrollContainer.getScrollForIndex(index);
3669+
let offset = this.verticalScrollContainer._virtScrollPosition - this.verticalScrollContainer.getScrollForIndex(index);
36703670
if (this.hasPinnedRecords && this.isRowPinningToTop) {
36713671
offset -= this.pinnedRowHeight;
36723672
}
@@ -8236,16 +8236,16 @@ export abstract class IgxGridBaseDirective implements GridType,
82368236
// recalc merged data
82378237
if (this.columnsToMerge.length > 0) {
82388238
const startIndex = this.verticalScrollContainer.state.startIndex;
8239-
const prevDataView = this.verticalScrollContainer.igxForOf?.slice(0, startIndex);
82408239
const data = [];
8241-
for (let index = 0; index < startIndex; index++) {
8242-
const rec = prevDataView[index];
8243-
if (rec.cellMergeMeta &&
8244-
// index + maxRowSpan is within view
8245-
startIndex < (index + Math.max(...rec.cellMergeMeta.values().toArray().map(x => x.rowSpan)))) {
8246-
const visibleIndex = this.isRowPinningToTop ? index + this.pinnedRecordsCount : index;
8247-
data.push({ record: rec, index: visibleIndex, dataIndex: index });
8248-
}
8240+
const rec = this.verticalScrollContainer.igxForOf[startIndex];
8241+
if (rec && rec.cellMergeMeta) {
8242+
this.columnsToMerge.forEach((col) => {
8243+
const root = rec.cellMergeMeta?.get(col.field)?.root;
8244+
if (root) {
8245+
data.push({ record: root, index: root.index, dataIndex: root.index });
8246+
}
8247+
})
8248+
82498249
}
82508250
this._mergedDataInView = data;
82518251
this.notifyChanges();

projects/igniteui-angular/grids/grid/src/grid.pipes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class IgxGridUnmergeActivePipe implements PipeTransform {
121121

122122
const result = cloneArray(collection) as any;
123123
uniqueRoots.forEach(x => {
124-
const index = collection.indexOf(x);
124+
const index = x.index;
125125
const colKeys = [...x.cellMergeMeta.keys()];
126126
const cols = colsToMerge.filter(col => colKeys.indexOf(col.field) !== -1);
127127
for (const col of cols) {

0 commit comments

Comments
 (0)