Skip to content

Commit b9689a1

Browse files
authored
Merge branch 'master' into ha-mutliview-calendar-2
2 parents 866557b + cb16744 commit b9689a1

File tree

7 files changed

+84
-17
lines changed

7 files changed

+84
-17
lines changed

projects/igniteui-angular/src/lib/core/grid-selection.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ export class IgxGridCRUDService {
151151
}
152152

153153
begin(cell): void {
154-
this.cell = this.createCell(cell);
155-
this.cell.primaryKey = this.primaryKey;
154+
const newCell = this.createCell(cell);
155+
newCell.primaryKey = this.primaryKey;
156156
const args = {
157-
cellID: this.cell.id,
158-
rowID: this.cell.id.rowID,
159-
oldValue: this.cell.value,
157+
cellID: newCell.id,
158+
rowID: newCell.id.rowID,
159+
oldValue: newCell.value,
160160
cancel: false
161161
};
162162

@@ -167,20 +167,22 @@ export class IgxGridCRUDService {
167167
return;
168168
}
169169

170-
171170
if (this.rowEditing) {
172-
if (!this.row) {
171+
if (this.row && !this.sameRow(newCell.id.rowID)) {
172+
this.grid.endEdit(true);
173+
this.cell = newCell;
173174
this.beginRowEdit();
174175
return;
175176
}
176177

177-
if (this.row && !this.sameRow(this.cell.id.rowID)) {
178-
this.grid.endEdit(true);
179-
this.cell = this.createCell(cell);
178+
this.cell = newCell;
179+
180+
if (!this.row) {
180181
this.beginRowEdit();
181182
return;
182183
}
183184
} else {
185+
this.cell = newCell;
184186
this.endRowEdit();
185187
}
186188
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class GridBaseAPIService <T extends IgxGridBaseComponent & IGridDataBinda
117117

118118
public submit_value() {
119119
const cell = this.grid.crudService.cell;
120-
if (cell) {
120+
if (cell ) {
121121
const args = this.update_cell(cell, cell.editValue);
122122
if (args.cancel) {
123123
return;

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -3845,8 +3845,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
38453845
}
38463846
this.gridAPI.escape_editMode();
38473847
}
3848-
3849-
this.notifyChanges();
3848+
this.cdr.detectChanges();
38503849
}
38513850
}
38523851
}
@@ -3872,7 +3871,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
38723871
}
38733872
const row = new IgxRow(rowSelector, -1, this.gridAPI.getRowData(rowSelector));
38743873
this.gridAPI.update_row(row, value);
3875-
this.notifyChanges();
3874+
this.cdr.detectChanges();
38763875
}
38773876
}
38783877

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

+40
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,46 @@ describe('IgxGrid - Cell Editing #grid', () => {
647647
expect(cell.editMode).toBe(true);
648648
});
649649

650+
it(`Should be able to update other cell in 'onCellEdit' event`, () => {
651+
grid.primaryKey = 'personNumber';
652+
fixture.detectChanges();
653+
654+
spyOn(grid.onCellEdit, 'emit').and.callThrough();
655+
grid.onCellEdit.subscribe((e: IGridEditEventArgs) => {
656+
if (e.cellID.columnID === 0) {
657+
grid.updateCell(1, e.rowID, 'age' );
658+
}
659+
});
660+
661+
let cell = grid.getCellByColumn(0, 'fullName');
662+
663+
UIInteractions.simulateClickAndSelectCellEvent(cell);
664+
fixture.detectChanges();
665+
666+
cell.nativeElement.dispatchEvent(new MouseEvent('dblclick'));
667+
fixture.detectChanges();
668+
669+
expect(cell.editMode).toBe(true);
670+
let editTemplate = fixture.debugElement.query(By.css('input'));
671+
UIInteractions.sendInput(editTemplate, 'New Name');
672+
fixture.detectChanges();
673+
674+
// press tab on edited cell
675+
UIInteractions.triggerKeyDownWithBlur('tab', cell.nativeElement, true);
676+
fixture.detectChanges();
677+
678+
expect(grid.onCellEdit.emit).toHaveBeenCalledTimes(2);
679+
cell = grid.getCellByColumn(0, 'age');
680+
expect(cell.editMode).toBe(true);
681+
expect(cell.value).toEqual(1);
682+
expect(cell.editValue).toEqual(1);
683+
editTemplate = fixture.debugElement.query(By.css('input'));
684+
expect(editTemplate.nativeElement.value).toEqual('1');
685+
686+
cell = grid.getCellByColumn(0, 'fullName');
687+
expect(cell.value).toEqual('New Name');
688+
});
689+
650690
it(`Should properly emit 'onCellEditCancel' event`, () => {
651691
spyOn(grid.onCellEditCancel, 'emit').and.callThrough();
652692
const cell = grid.getCellByColumn(0, 'fullName');

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

+27
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-row-selection.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1240,12 +1240,12 @@ describe('IgxGrid - Row Selection #grid', () => {
12401240
});
12411241

12421242
it('Should be able to update row through primaryKey', () => {
1243-
spyOn(grid.cdr, 'markForCheck').and.callThrough();
1243+
spyOn(grid.onRowEdit, 'emit').and.callThrough();
12441244
expect(grid.primaryKey).toBeTruthy();
12451245
expect(grid.rowList.length).toEqual(10, 'All 10 rows should initialized');
12461246
expect(grid.getRowByKey(2).rowData['JobTitle']).toMatch('Director');
12471247
grid.updateRow({ ID: 2, Name: 'Gilberto Todd', JobTitle: 'Vice President' }, 2);
1248-
expect(grid.cdr.markForCheck).toHaveBeenCalledTimes(1);
1248+
expect(grid.onRowEdit.emit).toHaveBeenCalledTimes(1);
12491249
fix.detectChanges();
12501250
expect(grid.getRowByIndex(1).rowData['JobTitle']).toMatch('Vice President');
12511251
expect(grid.getRowByKey(2).rowData['JobTitle']).toMatch('Vice President');

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

-1
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)