Skip to content

Commit ff8db9c

Browse files
authored
fix(igxGrid): Fix offset when using virtual scrollbar with ratio. (#17163)
1 parent 00f70ed commit ff8db9c

4 files changed

Lines changed: 22 additions & 18 deletions

File tree

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
@@ -3654,7 +3654,7 @@ export abstract class IgxGridBaseDirective implements GridType,
36543654

36553655
protected getMergeCellOffset(rowData) {
36563656
const index = rowData.dataIndex;
3657-
let offset = this.verticalScrollContainer.scrollPosition - this.verticalScrollContainer.getScrollForIndex(index);
3657+
let offset = this.verticalScrollContainer._virtScrollPosition - this.verticalScrollContainer.getScrollForIndex(index);
36583658
if (this.hasPinnedRecords && this.isRowPinningToTop) {
36593659
offset -= this.pinnedRowHeight;
36603660
}
@@ -8220,16 +8220,16 @@ export abstract class IgxGridBaseDirective implements GridType,
82208220
// recalc merged data
82218221
if (this.columnsToMerge.length > 0) {
82228222
const startIndex = this.verticalScrollContainer.state.startIndex;
8223-
const prevDataView = this.verticalScrollContainer.igxForOf?.slice(0, startIndex);
82248223
const data = [];
8225-
for (let index = 0; index < startIndex; index++) {
8226-
const rec = prevDataView[index];
8227-
if (rec.cellMergeMeta &&
8228-
// index + maxRowSpan is within view
8229-
startIndex < (index + Math.max(...rec.cellMergeMeta.values().toArray().map(x => x.rowSpan)))) {
8230-
const visibleIndex = this.isRowPinningToTop ? index + this.pinnedRecordsCount : index;
8231-
data.push({ record: rec, index: visibleIndex, dataIndex: index });
8232-
}
8224+
const rec = this.verticalScrollContainer.igxForOf[startIndex];
8225+
if (rec && rec.cellMergeMeta) {
8226+
this.columnsToMerge.forEach((col) => {
8227+
const root = rec.cellMergeMeta?.get(col.field)?.root;
8228+
if (root) {
8229+
data.push({ record: root, index: root.index, dataIndex: root.index });
8230+
}
8231+
})
8232+
82338233
}
82348234
this._mergedDataInView = data;
82358235
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)