Skip to content

Commit 3a049bf

Browse files
authored
Merge pull request #10116 from IgniteUI/mdragnev/fix-9994
Add rowAdd and rowDelete events
2 parents a0e631e + 349f398 commit 3a049bf

File tree

4 files changed

+60
-6
lines changed

4 files changed

+60
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@ All notable changes for each version of this project will be documented in this
2424
```
2525
- Added capability to restore the state of multi column headers with `IgxGridStateDirective`.
2626
- Introduced new 'rowStyles' and 'rowClasses' grid properties which allows to define a custom styling on each grid row
27+
- Introduced two new *cancellable* outputs related to CRUD - `rowDelete` and `rowAdd`. Both use an `IGridEditEventArgs` object as an event argument.
28+
```html
29+
<igx-grid #grid [data]="localData" (rowAdd)="rowAdd($event)" (rowDelete)="rowDelete($event)" [autoGenerate]="true"></igx-grid>
30+
```
2731
- `IgxSnackbarComponent`
2832
- Introduced new 'positionSettings' input which allows to define a custom animation and position.
2933
- `IgxToastComponent`
3034
- Introduced new 'positionSettings' input which allows to define a custom animation and position.
35+
3136
## 12.1.3
3237

3338
### New Features

projects/igniteui-angular/src/lib/action-strip/grid-actions/grid-editing-actions.component.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,7 @@ export class IgxGridEditingActionsComponent extends IgxGridActionsBaseDirective
127127
}
128128
const context = this.strip.context;
129129
const grid = context.grid;
130-
const record = grid.deleteRow(context.rowID);
131-
if (record !== null && record !== undefined) {
132-
// TODO: should we emit this when cascadeOnDelete is true for each row?!?!
133-
grid.rowDeleted.emit({ data: record });
134-
}
130+
grid.deleteRow(context.rowID);
135131

136132
this.strip.hide();
137133
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,12 @@ export class IgxRowCrudState extends IgxCellCrudState {
351351
rowEditArgs = this.grid.gridAPI.update_row(this.row, this.row.newData, event);
352352
nonCancelableArgs = this.rowEditDone(rowEditArgs.oldValue, event);
353353
} else {
354+
const rowAddArgs = this.row.createEditEventArgs(true, event);
355+
this.grid.rowAdd.emit(rowAddArgs);
356+
if (rowAddArgs.cancel) {
357+
return rowAddArgs;
358+
}
359+
354360
this.grid.transactions.endPending(false);
355361

356362
const parentId = this.getParentRowId();
@@ -467,6 +473,9 @@ export class IgxRowAddCrudState extends IgxRowCrudState {
467473
}
468474

469475
const args = super.endRowTransaction(commit, event);
476+
if (args.cancel) {
477+
return args;
478+
}
470479

471480
this.endAddRow();
472481
if (commit) {

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

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,34 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
741741
@Output()
742742
public rowDeleted = new EventEmitter<IRowDataEventArgs>();
743743

744+
/**
745+
* Emmited when deleting a row.
746+
*
747+
* @remarks
748+
* This event is cancelable.
749+
* Returns an `IGridEditEventArgs` object.
750+
* @example
751+
* ```html
752+
* <igx-grid #grid [data]="localData" (rowDelete)="rowDelete($event)" [height]="'305px'" [autoGenerate]="true"></igx-grid>
753+
* ```
754+
*/
755+
@Output()
756+
public rowDelete = new EventEmitter<IGridEditEventArgs>();
757+
758+
/**
759+
* Emmited just before the newly added row is commited.
760+
*
761+
* @remarks
762+
* This event is cancelable.
763+
* Returns an `IGridEditEventArgs` object.
764+
* @example
765+
* ```html
766+
* <igx-grid #grid [data]="localData" (rowAdd)="rowAdd($event)" [height]="'305px'" [autoGenerate]="true"></igx-grid>
767+
* ```
768+
*/
769+
@Output()
770+
public rowAdd = new EventEmitter<IGridEditEventArgs>();
771+
744772
/**
745773
* Emitted after column is resized.
746774
*
@@ -4466,7 +4494,23 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
44664494

44674495
/** @hidden */
44684496
public deleteRowById(rowId: any): any {
4469-
return this.gridAPI.deleteRowById(rowId);
4497+
const args = {
4498+
rowID: rowId,
4499+
cancel: false,
4500+
rowData: this.getRowData(rowId),
4501+
oldValue: null
4502+
};
4503+
this.rowDelete.emit(args);
4504+
if (args.cancel) {
4505+
return;
4506+
}
4507+
4508+
const record = this.gridAPI.deleteRowById(rowId);
4509+
if (record !== null && record !== undefined) {
4510+
// TODO: should we emit this when cascadeOnDelete is true for each row?!?!
4511+
this.rowDeleted.emit({ data: record });
4512+
}
4513+
return record;
44704514
}
44714515

44724516
/**

0 commit comments

Comments
 (0)