Skip to content

Commit 7e00c4b

Browse files
authored
Merge pull request #7288 from IgniteUI/skrastev/fix-7284-9.1.x
fix(igxGrid): Fix trying to perform horizontal scroll when passed index is not valid.
2 parents 5b67915 + 742456f commit 7e00c4b

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5662,7 +5662,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
56625662
}
56635663

56645664
/**
5665-
* Navigates to a posution in the grid based on provided `rowindex` and `visibleColumnIndex`.
5665+
* Navigates to a position in the grid based on provided `rowindex` and `visibleColumnIndex`.
56665666
* @remarks
56675667
* Also can execute a custom logic over the target element,
56685668
* through a callback function that accepts { targetType: GridKeydownTargetType, target: Object }

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ export class IgxGridNavigationService {
301301
}
302302

303303
public shouldPerformHorizontalScroll(visibleColIndex: number, rowIndex = -1) {
304+
if (visibleColIndex < 0 || visibleColIndex > this.grid.visibleColumns.length - 1) { return false; }
304305
if (rowIndex < 0 || rowIndex > this.grid.dataView.length - 1) {
305306
return !this.isColumnFullyVisible(visibleColIndex);
306307
}

projects/igniteui-angular/src/lib/grids/grid/grid.component.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,32 @@ describe('IgxGrid Component Tests #grid', () => {
15711571
prevCellCoords = grid.getPreviousCell(99, 0, (col) => col.editable);
15721572
expect(prevCellCoords).toEqual({ rowIndex: 99, visibleColumnIndex: 0 });
15731573
});
1574+
1575+
it('should not reset vertical scroll position when calling navigateTo with only rowIndex specified', async() => {
1576+
const fix = TestBed.createComponent(IgxGridDefaultRenderingComponent);
1577+
fix.componentInstance.initColumnsRows(15, 5);
1578+
fix.detectChanges();
1579+
1580+
const grid = fix.componentInstance.grid;
1581+
grid.height = '300px';
1582+
grid.width = '500px';
1583+
fix.detectChanges();
1584+
1585+
grid.navigateTo(0);
1586+
await wait();
1587+
fix.detectChanges();
1588+
1589+
grid.verticalScrollContainer.getScroll().scrollTop = 200;
1590+
await wait();
1591+
fix.detectChanges();
1592+
expect(grid.verticalScrollContainer.getScroll().scrollTop).toEqual(200);
1593+
1594+
grid.headerContainer.getScroll().scrollLeft = 100;
1595+
await wait();
1596+
fix.detectChanges();
1597+
1598+
expect(grid.verticalScrollContainer.getScroll().scrollTop).toEqual(200);
1599+
});
15741600
});
15751601

15761602
describe('IgxGrid - Integration with other Igx Controls', () => {

0 commit comments

Comments
 (0)