Skip to content

Commit 33f258f

Browse files
MayaKirovaMKirova
andauthored
fix(igxGrid): Update editValue if grid data is changed externally. (#15885)
* fix(igxGrid): Update editValue if grid data is changed externally. * chore(*): Update only if it's not in edit mode. * chore(*): Force change detection in grid test. --------- Co-authored-by: MKirova <MKirova@DEV-MKIROVA>
1 parent eca2d0f commit 33f258f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

projects/igniteui-angular/src/lib/grids/cell.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,10 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy, CellT
926926
this.highlight.lastSearchInfo.caseSensitive = this.grid.lastSearchInfo.caseSensitive;
927927
this.highlight.lastSearchInfo.exactMatch = this.grid.lastSearchInfo.exactMatch;
928928
}
929+
const isInEdit = this.grid.rowEditable ? this.row.inEditMode : this.editMode;
930+
if (this.formControl && this.formControl.value !== changes.value.currentValue && !isInEdit) {
931+
this.formControl.setValue(changes.value.currentValue);
932+
}
929933
}
930934
}
931935

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,27 @@ describe('IgxGrid - Cell Editing #grid', () => {
11651165
expect(cell.value).not.toEqual(cellValue);
11661166
expect(cell.value).toEqual(newValue);
11671167
});
1168+
1169+
it('should update editValue when externally changing grid data.', () => {
1170+
const cell = grid.getCellByColumn(0, 'fullName');
1171+
cell.editMode = true;
1172+
fixture.detectChanges();
1173+
1174+
expect(cell.editMode).toBeTruthy();
1175+
expect(cell.editValue).toBe('John Brown');
1176+
1177+
fixture.detectChanges();
1178+
cell.editMode = false;
1179+
fixture.detectChanges();
1180+
1181+
grid.data[0].fullName = "Test";
1182+
grid.cdr.detectChanges();
1183+
1184+
cell.editMode = true;
1185+
fixture.detectChanges();
1186+
expect(cell.editMode).toBeTruthy();
1187+
expect(cell.editValue).toBe('Test');
1188+
});
11681189
});
11691190

11701191
describe('Integration tests', () => {

0 commit comments

Comments
 (0)