Skip to content

Commit ca888ee

Browse files
authored
fix(igxTreeGrid): Re-eval correct row after collapsing. Add test. (#15329)
1 parent 73905e3 commit ca888ee

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

projects/igniteui-angular/src/lib/grids/common/crud.service.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,12 +684,13 @@ export class IgxGridCRUDService extends IgxRowAddCrudState {
684684
return;
685685
}
686686
this.endEdit(true, event);
687-
688-
if (parentRow != null && this.grid.expansionStates.get(parentRow.key)) {
689-
this.grid.collapseRow(parentRow.key);
687+
// work with copy of original row, since context may change on collapse.
688+
const parentRowCopy = parentRow ? Object.assign(copyDescriptors(parentRow), parentRow) : null;
689+
if (parentRowCopy != null && this.grid.expansionStates.get(parentRowCopy.key)) {
690+
this.grid.collapseRow(parentRowCopy.key);
690691
}
691692

692-
this.createAddRow(parentRow, asChild);
693+
this.createAddRow(parentRowCopy, asChild);
693694

694695
this.grid.transactions.startPending();
695696
if (this.addRowParent.isPinned) {

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { IgxActionStripComponent } from '../../action-strip/public_api';
99
import { IgxTreeGridRowComponent } from './tree-grid-row.component';
1010
import { first } from 'rxjs/operators';
1111
import { IRowDataCancelableEventArgs } from '../public_api';
12+
import { wait } from '../../test-utils/ui-interactions.spec';
1213

1314
describe('IgxTreeGrid - Add Row UI #tGrid', () => {
1415
configureTestSuite();
@@ -216,5 +217,47 @@ describe('IgxTreeGrid - Add Row UI #tGrid', () => {
216217
const addedRow = treeGrid.getRowByKey(newRowId);
217218
expect(addedRow.data[treeGrid.foreignKey]).toBe(2);
218219
});
220+
221+
it('should collapse row when child row adding begins and it added row should go under correct parent.', async() => {
222+
treeGrid.data = [
223+
{ ID: 1, ParentID: -1, Name: 'Casey Houston', JobTitle: 'Vice President', Age: 32 },
224+
{ ID: 2, ParentID: 10, Name: 'Gilberto Todd', JobTitle: 'Director', Age: 41 },
225+
{ ID: 3, ParentID: 10, Name: 'Tanya Bennett', JobTitle: 'Director', Age: 29 },
226+
{ ID: 4, ParentID: 6, Name: 'Jack Simon', JobTitle: 'Software Developer', Age: 33 },
227+
{ ID: 6, ParentID: -1, Name: 'Erma Walsh', JobTitle: 'CEO', Age: 52 },
228+
{ ID: 7, ParentID: 10, Name: 'Debra Morton', JobTitle: 'Associate Software Developer', Age: 35 },
229+
{ ID: 9, ParentID: 10, Name: 'Leslie Hansen', JobTitle: 'Associate Software Developer', Age: 44 },
230+
{ ID: 10, ParentID: -1, Name: 'Eduardo Ramirez', JobTitle: 'Manager', Age: 53 }
231+
];
232+
fix.detectChanges();
233+
treeGrid.collapseAll();
234+
treeGrid.height = "350px";
235+
fix.detectChanges();
236+
const parentRow1 = treeGrid.rowList.toArray()[1] as IgxTreeGridRowComponent;
237+
treeGrid.expandRow(parentRow1.key);
238+
const parentRow2 = treeGrid.rowList.toArray()[3] as IgxTreeGridRowComponent;
239+
treeGrid.expandRow(parentRow2.key);
240+
treeGrid.triggerPipes();
241+
fix.detectChanges();
242+
243+
// scroll bottom
244+
treeGrid.verticalScrollContainer.scrollTo(treeGrid.dataView.length - 1);
245+
await wait(50);
246+
fix.detectChanges();
247+
// start add row
248+
parentRow2.beginAddChild();
249+
fix.detectChanges();
250+
// last row should be add row
251+
const addRow = treeGrid.gridAPI.get_row_by_index(4);
252+
expect(addRow.addRowUI).toBeTrue();
253+
endTransition();
254+
255+
// end edit
256+
treeGrid.gridAPI.crudService.endEdit(true);
257+
fix.detectChanges();
258+
259+
// row should be added under correct parent
260+
expect(treeGrid.data[treeGrid.data.length - 1].ParentID).toBe(10);
261+
});
219262
});
220263
});

0 commit comments

Comments
 (0)