File tree Expand file tree Collapse file tree 2 files changed +34
-5
lines changed
projects/igniteui-angular/src/lib/grids Expand file tree Collapse file tree 2 files changed +34
-5
lines changed Original file line number Diff line number Diff line change @@ -297,6 +297,7 @@ export class IgxRowCrudState extends IgxCellCrudState {
297297 public closeRowEditingOverlay = new Subject ( ) ;
298298
299299 private _rowEditingBlocked = false ;
300+ private _rowEditingStarted = false ;
300301
301302 public get primaryKey ( ) : any {
302303 return this . grid . primaryKey ;
@@ -329,12 +330,17 @@ export class IgxRowCrudState extends IgxCellCrudState {
329330 if ( ! this . row ) {
330331 this . createRow ( this . cell ) ;
331332 }
332- const rowArgs = this . row . createEditEventArgs ( false , event ) ;
333333
334- this . grid . rowEditEnter . emit ( rowArgs ) ;
335- if ( rowArgs . cancel ) {
336- this . endEditMode ( ) ;
337- return true ;
334+ if ( ! this . _rowEditingStarted ) {
335+ const rowArgs = this . row . createEditEventArgs ( false , event ) ;
336+
337+ this . grid . rowEditEnter . emit ( rowArgs ) ;
338+ if ( rowArgs . cancel ) {
339+ this . endEditMode ( ) ;
340+ return true ;
341+ }
342+
343+ this . _rowEditingStarted = true ;
338344 }
339345
340346 this . row . transactionState = this . grid . transactions . getAggregatedValue ( this . row . id , true ) ;
@@ -435,6 +441,7 @@ export class IgxRowCrudState extends IgxCellCrudState {
435441 public endRowEdit ( ) {
436442 this . row = null ;
437443 this . rowEditingBlocked = false ;
444+ this . _rowEditingStarted = false ;
438445 }
439446
440447 /** Clears cell and row editing state and closes row editing template if it is open */
Original file line number Diff line number Diff line change @@ -482,6 +482,28 @@ describe('IgxGrid - Row Adding #grid', () => {
482482 expect ( grid . gridAPI . get_row_by_index ( 1 ) . addRowUI ) . toBeTrue ( ) ;
483483 } ) ;
484484
485+ it ( `Should emit 'rowEditEnter' only once while adding a new row` , ( ) => {
486+ spyOn ( grid . rowEditEnter , 'emit' ) . and . callThrough ( ) ;
487+ const row = grid . gridAPI . get_row_by_index ( 0 ) ;
488+ row . beginAddRow ( ) ;
489+ fixture . detectChanges ( ) ;
490+
491+ endTransition ( ) ;
492+
493+ const newRow = grid . gridAPI . get_row_by_index ( 1 ) ;
494+ expect ( newRow . addRowUI ) . toBeTrue ( ) ;
495+
496+ let targetCell = grid . gridAPI . get_cell_by_index ( 1 , 'ContactName' ) as any ;
497+ UIInteractions . simulateClickAndSelectEvent ( targetCell ) ;
498+ fixture . detectChanges ( ) ;
499+
500+ targetCell = grid . gridAPI . get_cell_by_index ( 1 , 'CompanyName' ) as any ;
501+ UIInteractions . simulateClickAndSelectEvent ( targetCell ) ;
502+ fixture . detectChanges ( ) ;
503+
504+ expect ( grid . rowEditEnter . emit ) . toHaveBeenCalledTimes ( 1 ) ;
505+ } ) ;
506+
485507 it ( 'Should scroll and start adding a row as the first one when using the public API method' , async ( ) => {
486508 await wait ( DEBOUNCETIME ) ;
487509 fixture . detectChanges ( ) ;
You can’t perform that action at this time.
0 commit comments