Skip to content

Commit 2604f96

Browse files
viktorkombovddinchevahanastasov
authored
fix(tree-grid): Enable displaying flat data when foreignKey is not set - 15.0.x (#12435)
* fix(tree-grid): Enable displaying flat data when foreignKey is not set * fix(tree-grid): remove fit from the unit test * fix(tree-grid): add check whether primaryKey is set Co-authored-by: Desislava Dincheva <[email protected]> Co-authored-by: Hristo <[email protected]>
1 parent 1d1a486 commit 2604f96

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
IgxTreeGridDefaultLoadingComponent,
1111
IgxTreeGridCellSelectionComponent,
1212
IgxTreeGridSummariesTransactionsComponent,
13-
IgxTreeGridNoDataComponent
13+
IgxTreeGridNoDataComponent,
14+
IgxTreeGridWithNoForeignKeyComponent
1415
} from '../../test-utils/tree-grid-components.spec';
1516
import { wait } from '../../test-utils/ui-interactions.spec';
1617
import { GridSelectionMode } from '../common/enums';
@@ -31,7 +32,8 @@ describe('IgxTreeGrid Component Tests #tGrid', () => {
3132
IgxTreeGridDefaultLoadingComponent,
3233
IgxTreeGridCellSelectionComponent,
3334
IgxTreeGridSummariesTransactionsComponent,
34-
IgxTreeGridNoDataComponent
35+
IgxTreeGridNoDataComponent,
36+
IgxTreeGridWithNoForeignKeyComponent
3537
],
3638
imports: [
3739
NoopAnimationsModule,
@@ -143,6 +145,14 @@ describe('IgxTreeGrid Component Tests #tGrid', () => {
143145

144146
expect(container.getAttribute('role')).toMatch('row');
145147
}));
148+
149+
it('should display flat data even if no foreignKey is set', () => {
150+
fix = TestBed.createComponent(IgxTreeGridWithNoForeignKeyComponent);
151+
grid = fix.componentInstance.treeGrid;
152+
fix.detectChanges();
153+
154+
expect(grid.dataView.length).toBeGreaterThan(0);
155+
});
146156
});
147157

148158
describe('Auto-generated columns', () => {

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ export class IgxTreeGridHierarchizingPipe implements PipeTransform {
2727
return collection;
2828
}
2929

30-
if (primaryKey && foreignKey) {
31-
hierarchicalRecords = this.hierarchizeFlatData(collection, primaryKey, foreignKey, treeGridRecordsMap, flatData);
32-
} else if (childDataKey) {
30+
if (childDataKey) {
3331
hierarchicalRecords = this.hierarchizeRecursive(collection, primaryKey, childDataKey, undefined,
3432
flatData, 0, treeGridRecordsMap);
33+
} else if (primaryKey) {
34+
hierarchicalRecords = this.hierarchizeFlatData(collection, primaryKey, foreignKey, treeGridRecordsMap, flatData);
3535
}
3636

3737
this.grid.flatData = this.grid.transactions.enabled ?
@@ -254,25 +254,24 @@ export class IgxTreeGridTransactionPipe implements PipeTransform {
254254
return collection;
255255
}
256256

257-
const foreignKey = this.grid.foreignKey;
258257
const childDataKey = this.grid.childDataKey;
259258

260-
if (foreignKey) {
261-
const flatDataClone = cloneArray(collection);
262-
return DataUtil.mergeTransactions(
263-
flatDataClone,
264-
aggregatedChanges,
265-
this.grid.primaryKey,
266-
this.grid.dataCloneStrategy);
267-
} else if (childDataKey) {
259+
if (childDataKey) {
268260
const hierarchicalDataClone = cloneHierarchicalArray(collection, childDataKey);
269261
return DataUtil.mergeHierarchicalTransactions(
270262
hierarchicalDataClone,
271263
aggregatedChanges,
272264
childDataKey,
273265
this.grid.primaryKey,
274266
this.grid.dataCloneStrategy
275-
);
267+
);
268+
} else {
269+
const flatDataClone = cloneArray(collection);
270+
return DataUtil.mergeTransactions(
271+
flatDataClone,
272+
aggregatedChanges,
273+
this.grid.primaryKey,
274+
this.grid.dataCloneStrategy);
276275
}
277276
}
278277
}

projects/igniteui-angular/src/lib/test-utils/tree-grid-components.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,23 @@ export class IgxTreeGridSummariesKeyScroliingComponent {
354354
public data = SampleTestData.employeeTreeDataPrimaryForeignKey();
355355
}
356356

357+
@Component({
358+
template: `
359+
<igx-tree-grid #treeGrid [data]="data" primaryKey="ID" width="400px" height="800px">
360+
<igx-column [field]="'ID'" width="150px" dataType="number"></igx-column>
361+
<igx-column [field]="'ParentID'" width="150px" dataType="number"></igx-column>
362+
<igx-column [field]="'Name'" width="150px" dataType="string"></igx-column>
363+
<igx-column [field]="'HireDate'" width="150px" dataType="date"></igx-column>
364+
<igx-column [field]="'Age'" width="150px" dataType="number"></igx-column>
365+
<igx-column [field]="'OnPTO'" width="150px" dataType="boolean"></igx-column>
366+
</igx-tree-grid>
367+
`
368+
})
369+
export class IgxTreeGridWithNoForeignKeyComponent {
370+
@ViewChild(IgxTreeGridComponent, { static: true }) public treeGrid: IgxTreeGridComponent;
371+
public data = SampleTestData.employeeTreeDataPrimaryForeignKey();
372+
}
373+
357374
@Component({
358375
template: `
359376
<igx-tree-grid #treeGrid [data]="data" primaryKey="ID" foreignKey="ParentID" expansionDepth="0"

0 commit comments

Comments
 (0)