Skip to content

Commit a2a95a9

Browse files
MKirovaMKirova
MKirova
authored and
MKirova
committed
chore(*): Fix issue with navigation in case details view contain a grid.
1 parent 1c3a068 commit a2a95a9

File tree

3 files changed

+23
-26
lines changed

3 files changed

+23
-26
lines changed

projects/igniteui-angular/src/lib/grids/common/grid.interface.ts

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface GridType extends IGridDataBindable {
2323
allowFiltering: boolean;
2424
rowDraggable: boolean;
2525
primaryKey: any;
26+
id: string;
2627

2728
filterMode: FilterMode;
2829

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

+21-5
Original file line numberDiff line numberDiff line change
@@ -650,13 +650,18 @@ export class IgxGridNavigationService {
650650
}
651651

652652
protected getRowByIndex(index, selector = this.getRowSelector()) {
653-
return this.grid.nativeElement.querySelector(
654-
`${selector}[data-rowindex="${index}"]`);
655-
}
653+
const gridTag = this.grid.nativeElement.tagName.toLocaleLowerCase();
654+
const row = Array.from(this.grid.nativeElement.querySelectorAll(
655+
`${selector}[data-rowindex="${index}"]`))
656+
.find(x => this.getClosestElemByTag(x, gridTag).getAttribute('id') === this.grid.id);
657+
return row;
658+
}
656659

657660
protected getNextRowByIndex(nextIndex) {
658-
return this.grid.tbody.nativeElement.querySelector(
659-
`[data-rowindex="${nextIndex}"]`);
661+
const gridTag = this.grid.nativeElement.tagName.toLocaleLowerCase();
662+
const row = Array.from(this.grid.tbody.nativeElement.querySelectorAll(
663+
`[data-rowindex="${nextIndex}"]`)).find(x => this.getClosestElemByTag(x, gridTag).getAttribute('id') === this.grid.id);
664+
return row;
660665
}
661666

662667
private getAllRows() {
@@ -674,4 +679,15 @@ export class IgxGridNavigationService {
674679
protected getRowSelector(): string {
675680
return 'igx-grid-row';
676681
}
682+
683+
protected getClosestElemByTag(sourceElem, targetTag) {
684+
let result = sourceElem;
685+
while (result !== null && result.nodeType === 1) {
686+
if (result.tagName.toLowerCase() === targetTag.toLowerCase()) {
687+
return result;
688+
}
689+
result = result.parentNode;
690+
}
691+
return null;
692+
}
677693
}

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

+1-21
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,7 @@ export class IgxHierarchicalGridNavigationService extends IgxGridNavigationServi
2020
}
2121

2222
protected getRowByIndex(index) {
23-
const selector = this.getRowSelector();
24-
const rows = Array.from(this.grid.nativeElement.querySelectorAll(
25-
`${selector}[data-rowindex="${index}"]`));
26-
let row;
27-
rows.forEach((r) => {
28-
const parentGrid = this.getClosestElemByTag(r, 'igx-hierarchical-grid');
29-
if (parentGrid && parentGrid.getAttribute('id') === this.grid.id) {
30-
row = r;
31-
}
32-
});
23+
const row = super.getRowByIndex(index) as any;
3324
return row;
3425
}
3526

@@ -798,17 +789,6 @@ export class IgxHierarchicalGridNavigationService extends IgxGridNavigationServi
798789
}
799790
}
800791

801-
private getClosestElemByTag(sourceElem, targetTag) {
802-
let result = sourceElem;
803-
while (result !== null && result.nodeType === 1) {
804-
if (result.tagName.toLowerCase() === targetTag.toLowerCase()) {
805-
return result;
806-
}
807-
result = result.parentNode;
808-
}
809-
return null;
810-
}
811-
812792
protected getNextRowByIndex(nextIndex) {
813793
return this.grid.dataRowList.find(element => element.index === nextIndex).element.nativeElement;
814794
}

0 commit comments

Comments
 (0)