Skip to content

Commit 2423d8f

Browse files
authored
fix(igxGrid): Emit new data for the rowAdd event args. (#13989)
1 parent 236229c commit 2423d8f

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export class IgxEditRow {
4141
rowID: this.id,
4242
primaryKey: this.id,
4343
rowKey: this.id,
44-
rowData: this.data,
45-
data: this.data,
44+
rowData: this.newData ?? this.data,
45+
data: this.newData ?? this.data,
4646
oldValue: this.data,
4747
cancel: false,
4848
owner: this.grid,

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { TestBed, fakeAsync, tick, waitForAsync } from '@angular/core/testing';
33
import { By } from '@angular/platform-browser';
44
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
55
import { IgxGridComponent } from './grid.component';
6-
import { IGridEditDoneEventArgs, IGridEditEventArgs } from '../common/events';
6+
import { IGridEditDoneEventArgs, IGridEditEventArgs, IRowDataCancelableEventArgs } from '../common/events';
77
import { IgxColumnComponent } from '../columns/column.component';
88
import { DisplayDensity } from '../../core/density';
99
import { UIInteractions, wait } from '../../test-utils/ui-interactions.spec';
@@ -299,6 +299,46 @@ describe('IgxGrid - Row Editing #grid', () => {
299299
expect(grid.rowEditDone.emit).toHaveBeenCalledWith(rowDoneArgs);
300300
});
301301

302+
it('Emit rowAdd event with proper arguments', () => {
303+
spyOn(grid.rowAdd, 'emit').and.callThrough();
304+
// start add row
305+
grid.beginAddRowById(null);
306+
fix.detectChanges();
307+
308+
const generatedId = grid.getRowByIndex(0).cells[0].value;
309+
310+
// enter edit mode of cell
311+
const prodCell = GridFunctions.getRowCells(fix, 0)[2];
312+
UIInteractions.simulateDoubleClickAndSelectEvent(prodCell);
313+
fix.detectChanges();
314+
315+
// input value
316+
const cellInput = (prodCell as any).nativeElement.querySelector('[igxinput]');
317+
UIInteractions.setInputElementValue(cellInput, "NewValue");
318+
fix.detectChanges();
319+
320+
// Done button click
321+
const doneButtonElement = GridFunctions.getRowEditingDoneButton(fix);
322+
doneButtonElement.click();
323+
fix.detectChanges();
324+
325+
// check event args
326+
const rowAddArgs: IRowDataCancelableEventArgs = {
327+
cancel: false,
328+
oldValue: { ProductID: generatedId},
329+
rowData: { ProductID: generatedId, ProductName: "NewValue"},
330+
data: { ProductID: generatedId, ProductName: "NewValue"},
331+
rowID: generatedId,
332+
primaryKey: generatedId,
333+
rowKey: generatedId,
334+
valid: true,
335+
event: jasmine.anything() as any,
336+
owner: grid,
337+
isAddRow: true
338+
}
339+
expect(grid.rowAdd.emit).toHaveBeenCalledWith(rowAddArgs);
340+
});
341+
302342
it('Should display the banner below the edited row if it is not the last one', () => {
303343
cell.editMode = true;
304344

0 commit comments

Comments
 (0)