Skip to content

Commit c379774

Browse files
authored
Merge branch 'master' into mdragnev/fix-add-row-id
2 parents 4c7c0f8 + a868784 commit c379774

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6659,7 +6659,8 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
66596659
if (args.cancel) {
66606660
return args.cancel;
66616661
}
6662-
this.gridAPI.addRowToData(row.data, this.addRowParent.asChild ? this.addRowParent.rowID : undefined);
6662+
const parentId = this._getParentRecordId();
6663+
this.gridAPI.addRowToData(row.data, parentId);
66636664
const doneArgs = row.createDoneEditEventArgs(cachedRowData);
66646665
this.rowEditDone.emit(doneArgs);
66656666
this.crudService.endRowEdit();
@@ -6685,6 +6686,14 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
66856686
return this.cancelAddMode;
66866687
}
66876688

6689+
/**
6690+
* @hidden
6691+
* @internal
6692+
*/
6693+
protected _getParentRecordId() {
6694+
return this.addRowParent.asChild ? this.addRowParent.rowID : undefined;
6695+
}
6696+
66886697
/**
66896698
* @hidden
66906699
* @internal

projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid-add-row-ui.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,23 @@ describe('IgxTreeGrid - Add Row UI #tGrid', () => {
9292
const addRow = treeGrid.getRowByIndex(2);
9393
expect(addRow.addRow).toBeTrue();
9494
});
95+
96+
it('should allow adding sibling to child row via the API.', () => {
97+
const row = treeGrid.rowList.toArray()[2] as IgxTreeGridRowComponent;
98+
// adds row as sibling
99+
row.beginAddRow();
100+
fix.detectChanges();
101+
endTransition();
102+
103+
treeGrid.endEdit(true);
104+
fix.detectChanges();
105+
106+
// check row is added as sibling
107+
expect(treeGrid.rowList.length).toBe(9);
108+
const addedRow = treeGrid.rowList.toArray()[4] as IgxTreeGridRowComponent;
109+
expect(addedRow.rowData.Name).toBe(undefined);
110+
// should have same parent record.
111+
expect(addedRow.treeRow.parent).toBe(row.treeRow.parent);
112+
});
95113
});
96114
});

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,19 @@ export class IgxTreeGridComponent extends IgxGridBaseDirective implements GridTy
519519
this.notifyChanges();
520520
}
521521

522+
/**
523+
* @hidden
524+
* @internal
525+
*/
526+
protected _getParentRecordId() {
527+
if (this.addRowParent.asChild) {
528+
return super._getParentRecordId();
529+
} else {
530+
const spawnedForRecord = this._gridAPI.get_rec_by_id(this.addRowParent.rowID);
531+
return spawnedForRecord.parent?.rowID;
532+
}
533+
}
534+
522535
/** @hidden */
523536
public deleteRowById(rowId: any) {
524537
// if this is flat self-referencing data, and CascadeOnDelete is set to true

0 commit comments

Comments
 (0)