Skip to content

Commit 325b5a3

Browse files
authored
fix(igxGrid): Fix merge cell offset when using virtual scrollbar with ratio. (#16331)
1 parent 2c6cb5f commit 325b5a3

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

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

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

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,11 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
271271
protected _differ: IterableDiffer<T> | null = null;
272272
protected _trackByFn: TrackByFunction<T>;
273273
protected individualSizeCache: number[] = [];
274+
/**
275+
* @hidden
276+
*/
274277
/** Internal track for scroll top that is being virtualized */
275-
protected _virtScrollPosition = 0;
278+
public _virtScrollPosition = 0;
276279
/** If the next onScroll event is triggered due to internal setting of scrollTop */
277280
protected _bScrollInternal = false;
278281
// End properties related to virtual height handling
@@ -867,7 +870,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
867870
const maxVirtScrollTop = this._virtSize - containerSize;
868871
this._bScrollInternal = true;
869872
this._virtScrollPosition = maxVirtScrollTop;
870-
this.scrollPosition = maxVirtScrollTop;
873+
this.scrollPosition = maxVirtScrollTop / this._virtRatio;
871874
return;
872875
}
873876
if (this._adjustToIndex) {
@@ -1470,11 +1473,12 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
14701473
let currentScroll = this.scrollPosition;
14711474
if (this._virtRatio !== 1) {
14721475
this._calcVirtualScrollPosition(this.scrollPosition);
1473-
currentScroll = this._virtScrollPosition;
1476+
scrollOffset = this.fixedUpdateAllElements(this._virtScrollPosition);
1477+
} else {
1478+
const scroll = this.scrollComponent.nativeElement;
1479+
scrollOffset = scroll && this.scrollComponent.size ?
1480+
currentScroll - this.sizesCache[this.state.startIndex] : 0;
14741481
}
1475-
const scroll = this.scrollComponent.nativeElement;
1476-
scrollOffset = scroll && this.scrollComponent.size ?
1477-
currentScroll - this.sizesCache[this.state.startIndex] : 0;
14781482
const dir = this.igxForScrollOrientation === 'horizontal' ? 'left' : 'top';
14791483
this.dc.instance._viewContainer.element.nativeElement.style[dir] = -(scrollOffset) + 'px';
14801484
}

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

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

37203720
protected getMergeCellOffset(rowData) {
37213721
const index = rowData.dataIndex;
3722-
let offset = this.verticalScrollContainer.scrollPosition - this.verticalScrollContainer.getScrollForIndex(index);
3722+
let offset = this.verticalScrollContainer._virtScrollPosition - this.verticalScrollContainer.getScrollForIndex(index);
37233723
if (this.hasPinnedRecords && this.isRowPinningToTop) {
37243724
offset -= this.pinnedRowHeight;
37253725
}
@@ -8258,16 +8258,16 @@ export abstract class IgxGridBaseDirective implements GridType,
82588258
// recalc merged data
82598259
if (this.columnsToMerge.length > 0) {
82608260
const startIndex = this.verticalScrollContainer.state.startIndex;
8261-
const prevDataView = this.verticalScrollContainer.igxForOf?.slice(0, startIndex);
82628261
const data = [];
8263-
for (let index = 0; index < startIndex; index++) {
8264-
const rec = prevDataView[index];
8265-
if (rec.cellMergeMeta &&
8266-
// index + maxRowSpan is within view
8267-
startIndex < (index + Math.max(...rec.cellMergeMeta.values().toArray().map(x => x.rowSpan)))) {
8268-
const visibleIndex = this.isRowPinningToTop ? index + this.pinnedRecordsCount : index;
8269-
data.push({ record: rec, index: visibleIndex, dataIndex: index });
8270-
}
8262+
const rec = this.verticalScrollContainer.igxForOf[startIndex];
8263+
if (rec && rec.cellMergeMeta) {
8264+
this.columnsToMerge.forEach((col) => {
8265+
const root = rec.cellMergeMeta?.get(col.field)?.root;
8266+
if (root) {
8267+
data.push({ record: root, index: root.index, dataIndex: root.index });
8268+
}
8269+
})
8270+
82718271
}
82728272
this._mergedDataInView = data;
82738273
this.notifyChanges();

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

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

133133
let result = cloneArray(collection) as any;
134134
uniqueRoots.forEach(x => {
135-
const index = collection.indexOf(x);
135+
const index = x.index;
136136
const colKeys = [...x.cellMergeMeta.keys()];
137137
const cols = colsToMerge.filter(col => colKeys.indexOf(col.field) !== -1);
138138
for (const col of cols) {

0 commit comments

Comments
 (0)