Skip to content

Commit 78bc4fe

Browse files
authored
Merge pull request #12498 from IgniteUI/mdragnev/fix-12189
Fix(grid): Do not clear neither transactions nor newData when canceling rowEdit …
2 parents 51948a3 + d24903d commit 78bc4fe

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,6 @@ export class IgxRowCrudState extends IgxCellCrudState {
375375
this.updateRowEditData(this.row, this.row.newData);
376376
args = this.rowEdit(event);
377377
if (args.cancel) {
378-
delete this.row.newData;
379-
this.grid.transactions.clear(this.row.id);
380378
return args;
381379
}
382380
}
@@ -583,7 +581,7 @@ export class IgxGridCRUDService extends IgxRowAddCrudState {
583581
return;
584582
}
585583

586-
if (this.nonEditable){
584+
if (this.nonEditable) {
587585
console.warn('The grid must have a `primaryKey` specified when using `rowEditable`!');
588586
return;
589587
}
@@ -695,10 +693,13 @@ export class IgxGridCRUDService extends IgxRowAddCrudState {
695693
return args.cancel;
696694
}
697695
} else {
696+
// needede because this.cell is null after exitCellEdit
697+
// thus the next if is always false
698+
const cell = this.cell;
698699
this.exitCellEdit(event);
699-
if (!this.grid.rowEditable && this.cell) {
700-
const value = this.grid.transactions.getAggregatedValue(this.cell.id.rowID, true) || this.cell.rowData;
701-
this.grid.validation.update(this.cell.id.rowID, value);
700+
if (!this.grid.rowEditable && cell) {
701+
const value = this.grid.transactions.getAggregatedValue(cell.id.rowID, true) || cell.rowData;
702+
this.grid.validation.update(cell.id.rowID, value);
702703
}
703704
}
704705

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
15581558
* ```
15591559
*/
15601560
public set sortDescendingHeaderIconTemplate(template: TemplateRef<IgxGridHeaderTemplateContext>) {
1561-
this._sortDescendingHeaderIconTemplate = template;
1561+
this._sortDescendingHeaderIconTemplate = template;
15621562
}
15631563

15641564
/**
@@ -4445,12 +4445,12 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
44454445
*/
44464446
public recalculateAutoSizes() {
44474447
// reset auto-size and calculate it again.
4448-
this._columns.forEach( x => x.autoSize = undefined);
4449-
this.resetCaches();
4450-
this.zone.onStable.pipe(first()).subscribe(() => {
4451-
this.cdr.detectChanges();
4452-
this.autoSizeColumnsInView();
4453-
});
4448+
this._columns.forEach(x => x.autoSize = undefined);
4449+
this.resetCaches();
4450+
this.zone.onStable.pipe(first()).subscribe(() => {
4451+
this.cdr.detectChanges();
4452+
this.autoSizeColumnsInView();
4453+
});
44544454
}
44554455

44564456
/**
@@ -6516,6 +6516,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
65166516

65176517
});
65186518
}
6519+
65196520
this.selectionService.clearHeaderCBState();
65206521
this.summaryService.clearSummaryCache();
65216522
this.pipeTrigger++;
@@ -7062,8 +7063,8 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
70627063
this.tbody.nativeElement.style.display = 'none';
70637064
const parentElement = this.nativeElement.parentElement || (this.nativeElement.getRootNode() as any).host;
70647065
let res = !parentElement ||
7065-
parentElement.clientHeight === 0 ||
7066-
parentElement.clientHeight === renderedHeight;
7066+
parentElement.clientHeight === 0 ||
7067+
parentElement.clientHeight === renderedHeight;
70677068
if ((!this.platform.isChromium && !this.platform.isFirefox) || this._autoSize) {
70687069
// If grid causes the parent container to extend (for example when container is flex)
70697070
// we should always auto-size since the actual size of the container will continuously change as the grid renders elements.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1715,11 +1715,13 @@ describe('IgxGrid - Row Editing #grid', () => {
17151715
// On button click
17161716
const doneButtonElement = GridFunctions.getRowEditingDoneButton(fix);
17171717
doneButtonElement.click();
1718+
fix.detectChanges();
17181719

17191720
const rowData = Object.assign({}, cell.row.data, { ProductName: 'New Name' });
17201721
expect(!!grid.gridAPI.crudService.rowInEditMode).toEqual(true);
17211722
expect(grid.gridAPI.crudService.cellInEditMode).toEqual(false);
1722-
expect(cell.row.data).not.toEqual(rowData);
1723+
expect(cell.row.data.ProductName).toEqual('New Name');
1724+
expect(grid.dataView[0]).not.toEqual(rowData);
17231725
});
17241726

17251727
it(`Should properly emit 'rowEdit' event - Button Click`, () => {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ describe('IgxGrid - Validation #grid', () => {
247247
fixture.detectChanges();
248248

249249
GridFunctions.verifyCellValid(cell, false);
250-
expect(grid.validationStatusChange.emit).toHaveBeenCalledWith({ status: 'INVALID', owner: grid});
250+
expect(grid.validationStatusChange.emit).toHaveBeenCalledWith({ status: 'INVALID', owner: grid });
251251

252252
UIInteractions.simulateDoubleClickAndSelectEvent(cell.element);
253253
cell.editMode = true;
@@ -259,7 +259,7 @@ describe('IgxGrid - Validation #grid', () => {
259259
fixture.detectChanges();
260260

261261
GridFunctions.verifyCellValid(cell, true);
262-
expect(grid.validationStatusChange.emit).toHaveBeenCalledWith({ status: 'INVALID', owner: grid});
262+
expect(grid.validationStatusChange.emit).toHaveBeenCalledWith({ status: 'INVALID', owner: grid });
263263
});
264264

265265
it('should return invalid transaction using the transaction service API', () => {
@@ -407,7 +407,7 @@ describe('IgxGrid - Validation #grid', () => {
407407
const grid = fixture.componentInstance.grid as IgxGridComponent;
408408
let cell = grid.gridAPI.get_cell_by_visible_index(1, 1);
409409

410-
grid.updateCell('IG', 2,'ProductName');
410+
grid.updateCell('IG', 2, 'ProductName');
411411
grid.validation.markAsTouched(2);
412412
fixture.detectChanges();
413413

0 commit comments

Comments
 (0)