Skip to content

Commit 57b5b1a

Browse files
authored
Merge branch 'master' into ddincheva/summaryChangelog
2 parents ac46df8 + 18eddff commit 57b5b1a

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,8 @@ export class GridBaseAPIService <T extends IgxGridBaseDirective & GridType> {
198198
row.data = { ...row.data, ...rowInEditMode.transactionState };
199199
// TODO: Workaround for updating a row in edit mode through the API
200200
} else if (this.grid.transactions.enabled) {
201-
const lastCommitedValue = grid.transactions.getState(row.id) ?
202-
grid.transactions.getState(row.id).value : null;
203-
row.data = lastCommitedValue ? Object.assign(row.data, lastCommitedValue) : row.data;
201+
const state = grid.transactions.getState(row.id);
202+
row.data = state ? Object.assign({}, row.data, state.value) : row.data;
204203
}
205204
}
206205

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,44 @@ describe('IgxGrid - Cell Editing #grid', () => {
694694
expect(cell.value).toEqual('New Name');
695695
});
696696

697+
it(`Should not update data in grid with transactions, when row is updated in onCellEdit and onCellEdit is canceled`, () => {
698+
fixture = TestBed.createComponent(SelectionWithTransactionsComponent);
699+
fixture.detectChanges();
700+
grid = fixture.componentInstance.grid;
701+
702+
grid.primaryKey = 'ID';
703+
fixture.detectChanges();
704+
705+
// update the cell value via updateRow and cancel the event
706+
grid.onCellEdit.subscribe((e: IGridEditEventArgs) => {
707+
const rowIndex: number = e.cellID.rowIndex;
708+
const row = grid.getRowByIndex(rowIndex);
709+
grid.updateRow({[row.columns[e.cellID.columnID].field]: e.newValue}, row.rowID);
710+
e.cancel = true;
711+
});
712+
713+
const cell = grid.getCellByColumn(0, 'Name');
714+
const initialValue = cell.value;
715+
const firstNewValue = 'New Value';
716+
const secondNewValue = 'Very New Value';
717+
718+
cell.update(firstNewValue);
719+
fixture.detectChanges();
720+
expect(cell.value).toBe(firstNewValue);
721+
722+
cell.update(secondNewValue);
723+
fixture.detectChanges();
724+
expect(cell.value).toBe(secondNewValue);
725+
726+
grid.transactions.undo();
727+
fixture.detectChanges();
728+
expect(cell.value).toBe(firstNewValue);
729+
730+
grid.transactions.undo();
731+
fixture.detectChanges();
732+
expect(cell.value).toBe(initialValue);
733+
});
734+
697735
it(`Should properly emit 'onCellEditCancel' event`, () => {
698736
spyOn(grid.onCellEditCancel, 'emit').and.callThrough();
699737
const cell = grid.getCellByColumn(0, 'fullName');

0 commit comments

Comments
 (0)