Skip to content

Commit 6996c2a

Browse files
authored
Merge pull request #8212 from IgniteUI/pbozhinov/fix-8052-10.2
NavigateTo fails to scroll to targeted row in MRL context scenario
2 parents 9c11c8b + fd950f5 commit 6996c2a

File tree

3 files changed

+41
-16
lines changed

3 files changed

+41
-16
lines changed

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,7 +2763,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
27632763
});
27642764

27652765
this.hideOverlays();
2766-
const args: IGridScrollEventArgs = { direction: 'horizontal', event: event, scrollPosition: this.headerContainer.scrollPosition };
2766+
const args: IGridScrollEventArgs = { direction: 'horizontal', event: event, scrollPosition: this.headerContainer.scrollPosition };
27672767
this.onScroll.emit(args);
27682768
}
27692769

@@ -2953,7 +2953,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
29532953
const destructor = takeUntil<any>(this.destroy$);
29542954
fromEvent(this.nativeElement, 'focusout').pipe(filter(() => !!this.navigation.activeNode), destructor).subscribe((event) => {
29552955
if (!this.crudService.cell && !!this.navigation.activeNode && (event.target === this.tbody.nativeElement &&
2956-
this.navigation.activeNode.row >= 0 && this.navigation.activeNode.row < this.dataView.length)
2956+
this.navigation.activeNode.row >= 0 && this.navigation.activeNode.row < this.dataView.length)
29572957
|| (event.target === this.theadRow.nativeElement && this.navigation.activeNode.row === -1)
29582958
|| (event.target === this.tfoot.nativeElement && this.navigation.activeNode.row === this.dataView.length)) {
29592959
this.navigation.activeNode = {} as IActiveNode;
@@ -3687,7 +3687,10 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
36873687
}
36883688

36893689
public getColumnByVisibleIndex(index: number): IgxColumnComponent {
3690-
return this.visibleColumns.find((col) => !col.columnGroup && !col.columnLayout && col.visibleIndex === index);
3690+
return this.visibleColumns.find((col) =>
3691+
!col.columnGroup && !col.columnLayout &&
3692+
col.visibleIndex === index
3693+
);
36913694
}
36923695

36933696
/**
@@ -3979,7 +3982,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
39793982
}
39803983

39813984
if (!target.pinned && !column.pinned) {
3982-
this._reorderColumns(column, target, pos, this._unpinnedColumns);
3985+
this._reorderColumns(column, target, pos, this._unpinnedColumns);
39833986
}
39843987

39853988
this._moveColumns(column, target, pos);
@@ -4814,8 +4817,8 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
48144817
protected getTheadRowHeight(): number {
48154818
const height = this.getComputedHeight(this.theadRow.nativeElement);
48164819
return (!this.allowFiltering || (this.allowFiltering && this.filterMode !== FilterMode.quickFilter)) ?
4817-
height - this.getFilterCellHeight() :
4818-
height;
4820+
height - this.getFilterCellHeight() :
4821+
height;
48194822
}
48204823

48214824
/**
@@ -4826,7 +4829,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
48264829
if (this.showToolbar && this.toolbarHtml != null) {
48274830
const height = this.getComputedHeight(this.toolbarHtml.nativeElement);
48284831
toolbarHeight = this.toolbarHtml.nativeElement.firstElementChild ?
4829-
height : 0;
4832+
height : 0;
48304833
}
48314834
return toolbarHeight;
48324835
}
@@ -4839,7 +4842,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
48394842
if (this.footer) {
48404843
const height = this.getComputedHeight(this.footer.nativeElement);
48414844
pagingHeight = this.footer.nativeElement.firstElementChild ?
4842-
height : 0;
4845+
height : 0;
48434846
}
48444847
return pagingHeight;
48454848
}
@@ -5999,7 +6002,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
59996002
}
60006003

60016004
if (this.dataView[rowIndex].detailsData) {
6002-
this.navigation.setActiveNode({row: rowIndex});
6005+
this.navigation.setActiveNode({ row: rowIndex });
60036006
this.cdr.detectChanges();
60046007
}
60056008

@@ -6545,11 +6548,11 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
65456548
}
65466549
if (commit) {
65476550
this.onRowAdded.subscribe(rowData => {
6548-
// A check whether the row is in the current view
6549-
const index = this.dataView.findIndex(data => data === rowData);
6550-
const shouldScroll = this.navigation.shouldPerformVerticalScroll(index, 0);
6551-
const showIndex = shouldScroll ? index : -1;
6552-
this.showSnackbarFor(showIndex);
6551+
// A check whether the row is in the current view
6552+
const index = this.dataView.findIndex(data => data === rowData);
6553+
const shouldScroll = this.navigation.shouldPerformVerticalScroll(index, 0);
6554+
const showIndex = shouldScroll ? index : -1;
6555+
this.showSnackbarFor(showIndex);
65536556
});
65546557
this.gridAPI.submit_add_value();
65556558
this.gridAPI.addRowToData(row.data);

projects/igniteui-angular/src/lib/grids/grid-mrl-navigation.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ export class IgxGridMRLNavigationService extends IgxGridNavigationService {
7676

7777
public shouldPerformVerticalScroll(targetRowIndex: number, visibleColIndex: number): boolean {
7878
if (!super.shouldPerformVerticalScroll(targetRowIndex, visibleColIndex)) { return false; }
79-
if (!this.isDataRow(targetRowIndex)) { return super.shouldPerformVerticalScroll(targetRowIndex, visibleColIndex); }
79+
if (!this.isDataRow(targetRowIndex) || visibleColIndex < 0) {
80+
return super.shouldPerformVerticalScroll(targetRowIndex, visibleColIndex);
81+
}
8082

8183
const targetRow = super.getRowElementByIndex(targetRowIndex);
8284
const containerHeight = this.grid.calcHeight ? Math.ceil(this.grid.calcHeight) : 0;
@@ -144,7 +146,7 @@ export class IgxGridMRLNavigationService extends IgxGridNavigationService {
144146

145147
public performVerticalScrollToCell(rowIndex: number, visibleColIndex: number, cb?: () => void) {
146148
const children = this.parentByChildIndex(visibleColIndex || 0)?.children;
147-
if (!super.isDataRow(rowIndex) || (children && children.length < 2)) {
149+
if (!super.isDataRow(rowIndex) || (children && children.length < 2) || visibleColIndex < 0) {
148150
return super.performVerticalScrollToCell(rowIndex, visibleColIndex, cb);
149151
}
150152

projects/igniteui-angular/src/lib/grids/grid/grid.multi-row-layout.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const GRID_COL_THEAD_CLASS = '.igx-grid__th';
1717
const GRID_MRL_BLOCK = '.igx-grid__mrl-block';
1818

1919
describe('IgxGrid - multi-row-layout #grid', () => {
20+
const DEBOUNCETIME = 60;
2021
configureTestSuite();
2122
beforeAll(async(() => {
2223
TestBed.configureTestingModule({
@@ -1144,6 +1145,25 @@ describe('IgxGrid - multi-row-layout #grid', () => {
11441145
expect(pos.rowIndex).toEqual(0);
11451146
expect(pos.visibleColumnIndex).toEqual(2);
11461147
}));
1148+
1149+
it('should navigate to the proper row in MRL scenario', (async () => {
1150+
const fix = TestBed.createComponent(ColumnLayoutTestComponent);
1151+
const grid = fix.componentInstance.grid;
1152+
const NAVIGATE = 20;
1153+
1154+
fix.detectChanges();
1155+
await wait(DEBOUNCETIME);
1156+
1157+
grid.navigateTo(NAVIGATE);
1158+
1159+
await wait(DEBOUNCETIME);
1160+
fix.detectChanges();
1161+
1162+
expect(grid.verticalScrollContainer.getScroll().scrollTop).toBeGreaterThan(0);
1163+
1164+
const row = grid.getRowByIndex(NAVIGATE);
1165+
expect(GridFunctions.elementInGridView(grid, row.nativeElement)).toBeTruthy();
1166+
}));
11471167
});
11481168

11491169
@Component({

0 commit comments

Comments
 (0)