Skip to content

Commit 2ab4d30

Browse files
authored
Merge pull request #12122 from IgniteUI/mkirova/feat-12116
feat(igxHierarchicalGrid): Allow binding row-island key property to complex objects.
2 parents 924b583 + 1d380ea commit 2ab4d30

File tree

4 files changed

+65
-4
lines changed

4 files changed

+65
-4
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Inject, Pipe, PipeTransform } from '@angular/core';
2-
import { cloneArray } from '../../core/utils';
2+
import { cloneArray, resolveNestedPath } from '../../core/utils';
33
import { DataUtil } from '../../data-operations/data-util';
44
import { GridPagingMode } from '../common/enums';
55
import { GridType, IGX_GRID_BASE } from '../common/grid.interface';
@@ -41,7 +41,8 @@ export class IgxGridHierarchicalPipe implements PipeTransform {
4141
if (!v[childKey]) {
4242
v[childKey] = [];
4343
}
44-
const childData = v[childKey];
44+
const hasNestedPath = childKey?.includes('.');
45+
const childData = !hasNestedPath ? v[childKey] : resolveNestedPath(v, childKey);
4546
childGridsData[childKey] = childData;
4647
});
4748
if (grid.gridAPI.get_row_expansion_state(v)) {

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,66 @@ describe('IgxHierarchicalGrid Row Islands #hGrid', () => {
919919
expect(childGrid1.rowList.length).toEqual(1);
920920
expect(childGrid1.gridAPI.get_cell_by_index(0, 'ProductName').nativeElement.innerText).toEqual('Child12 ProductName');
921921
}));
922+
923+
it('should allow binding to complex object.', fakeAsync(() => {
924+
const rowIsland1 = fixture.componentInstance.rowIsland1 as IgxRowIslandComponent;
925+
const rowIsland2 = fixture.componentInstance.rowIsland2 as IgxRowIslandComponent;
926+
rowIsland1.key = 'childData.Records';
927+
rowIsland2.key = 'childData2.Records';
928+
929+
hierarchicalGrid.childLayoutKeys = ['childData.Records', 'childData2.Records'];
930+
const complexObjData = [
931+
{
932+
ID: 1,
933+
ProductName : 'Parent Name',
934+
childData: {
935+
Records: [
936+
{
937+
ID: 11,
938+
ProductName : 'Child11 ProductName'
939+
},
940+
{
941+
ID: 12,
942+
ProductName : 'Child12 ProductName'
943+
}
944+
]
945+
},
946+
childData2: {
947+
Records: [
948+
{
949+
ID: 21,
950+
Col1: 'Child21 Col1',
951+
Col2: 'Child21 Col2',
952+
Col3: 'Child21 Col3'
953+
},
954+
{
955+
ID: 22,
956+
Col1: 'Child22 Col1',
957+
Col2: 'Child22 Col2',
958+
Col3: 'Child22 Col3'
959+
}
960+
]
961+
}
962+
}
963+
];
964+
fixture.componentInstance.data = complexObjData;
965+
fixture.detectChanges();
966+
967+
const row = hierarchicalGrid.gridAPI.get_row_by_index(0) as IgxHierarchicalRowComponent;
968+
UIInteractions.simulateClickAndSelectEvent(row.expander);
969+
tick();
970+
fixture.detectChanges();
971+
972+
const childGrids = fixture.debugElement.queryAll(By.css('igx-child-grid-row'));
973+
const childGrid1 = childGrids[0].query(By.css('igx-hierarchical-grid')).componentInstance;
974+
const childGrid2 = childGrids[1].query(By.css('igx-hierarchical-grid')).componentInstance;
975+
expect(childGrid1.data.length).toEqual(2);
976+
expect(childGrid2.data.length).toEqual(2);
977+
978+
expect(childGrid1.data[0].ID).toBe(11);
979+
expect(childGrid2.data[0].ID).toBe(21);
980+
})
981+
);
922982
});
923983

924984
describe('IgxHierarchicalGrid Children Sizing #hGrid', () => {

src/app/hierarchical-grid/hierarchical-grid.sample.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,4 @@ <h4 class="sample-title">Sample 4</h4>
180180
<igx-column *ngFor="let c of childColumns" [field]="c"></igx-column>
181181
</igx-row-island>
182182
</igx-hierarchical-grid>
183-
</div>
183+
</div>

src/app/hierarchical-grid/hierarchical-grid.sample.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,4 @@ export class HierarchicalGridSampleComponent implements AfterViewInit {
177177
row.pin();
178178
}
179179
}
180-
}
180+
}

0 commit comments

Comments
 (0)