Skip to content

Commit 998fef6

Browse files
committed
fix(grid): call markForCheck when update cell or row #5763
1 parent ea666cd commit 998fef6

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

projects/igniteui-angular/src/lib/grids/api.service.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,12 @@ export class GridBaseAPIService <T extends IgxGridBaseComponent & IGridDataBinda
117117

118118
public submit_value() {
119119
const cell = this.grid.crudService.cell;
120-
if (cell) {
121-
const args = this.update_cell(cell, cell.editValue);
122-
if (args.cancel) {
123-
return;
120+
if (cell ) {
121+
if (!(isEqual(cell.value, cell.editValue))) {
122+
const args = this.update_cell(cell, cell.editValue);
123+
if (args.cancel) {
124+
return;
125+
}
124126
}
125127
this.escape_editMode();
126128
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3690,8 +3690,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
36903690
}
36913691
this.gridAPI.escape_editMode();
36923692
}
3693-
3694-
this.notifyChanges();
3693+
this.cdr.markForCheck();
36953694
}
36963695
}
36973696
}
@@ -3717,7 +3716,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
37173716
}
37183717
const row = new IgxRow(rowSelector, -1, this.gridAPI.getRowData(rowSelector));
37193718
this.gridAPI.update_row(row, value);
3720-
this.notifyChanges();
3719+
this.cdr.markForCheck();
37213720
}
37223721
}
37233722

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,6 +1809,33 @@ describe('IgxGrid - Row Editing #grid', () => {
18091809
cancel: false
18101810
});
18111811
}));
1812+
1813+
it(`Should properly emit 'onCellEdit' event `, fakeAsync(() => {
1814+
spyOn(grid.onCellEdit, 'emit').and.callThrough();
1815+
spyOn(grid.onRowEdit, 'emit').and.callThrough();
1816+
1817+
let cell = grid.getCellByColumn(0, 'ProductName');
1818+
const cellArgs = { cellID: cell.cellID, rowID: cell.row.rowID, oldValue: 'Chai', newValue: 'New Value', cancel: false };
1819+
1820+
cell.nativeElement.dispatchEvent(new MouseEvent('dblclick'));
1821+
tick(16);
1822+
fix.detectChanges();
1823+
1824+
expect(cell.editMode).toBe(true);
1825+
const editTemplate = fix.debugElement.query(By.css('input'));
1826+
UIInteractions.sendInput(editTemplate, 'New Value');
1827+
fix.detectChanges();
1828+
1829+
// Click on cell in different row
1830+
cell = grid.getCellByColumn(2, 'ProductName');
1831+
UIInteractions.simulateClickAndSelectCellEvent(cell);
1832+
tick(16);
1833+
fix.detectChanges();
1834+
1835+
expect(grid.onRowEdit.emit).toHaveBeenCalledTimes(1);
1836+
expect(grid.onCellEdit.emit).toHaveBeenCalledTimes(1);
1837+
expect(grid.onCellEdit.emit).toHaveBeenCalledWith(cellArgs);
1838+
}));
18121839
});
18131840

18141841
describe('Column editable property', () => {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,6 @@ export class IgxGridComponent extends IgxGridBaseComponent implements IGridDataB
566566
*/
567567
public groupBy(expression: IGroupingExpression | Array<IGroupingExpression>): void {
568568
this.endEdit(true);
569-
this._gridAPI.submit_value();
570569
if (expression instanceof Array) {
571570
this._gridAPI.groupBy_multiple(expression);
572571
} else {

0 commit comments

Comments
 (0)