Skip to content

Commit edb5404

Browse files
authored
Merge pull request #15814 from IgniteUI/mdragnev/fix-rowAddTextTemplate
fix(crud): Change how we differentiate between add and edit row
2 parents 8e6d873 + 1fd2f06 commit edb5404

File tree

9 files changed

+24
-22
lines changed

9 files changed

+24
-22
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,12 @@ export class IgxEditRow {
7373
return args;
7474
}
7575

76-
public getClassName() {
77-
return this.constructor.name;
76+
public get isAddRow(): boolean {
77+
return false;
7878
}
7979
}
8080

8181
export class IgxAddRow extends IgxEditRow {
82-
public isAddRow = true;
83-
8482
constructor(id: any,
8583
index: number,
8684
data: any,
@@ -102,6 +100,10 @@ export class IgxAddRow extends IgxEditRow {
102100
args.isAddRow = true;
103101
return args;
104102
}
103+
104+
public override get isAddRow(): boolean {
105+
return true;
106+
}
105107
}
106108

107109
export interface IgxAddRowParent {
@@ -376,7 +378,7 @@ export class IgxRowCrudState extends IgxCellCrudState {
376378

377379
/** Enters row edit mode */
378380
public beginRowEdit(event?: Event) {
379-
if (!this.row || !(this.row.getClassName() === IgxEditRow.name)) {
381+
if (!this.row || this.row.isAddRow) {
380382
if (!this.row) {
381383
this.createRow(this.cell);
382384
}
@@ -437,14 +439,14 @@ export class IgxRowCrudState extends IgxCellCrudState {
437439
let nonCancelableArgs;
438440
if (!commit) {
439441
this.grid.transactions.endPending(false);
440-
const isAddRow = this.row && this.row.getClassName() === IgxAddRow.name;
442+
const isAddRow = this.row && this.row.isAddRow;
441443
const id = this.row ? this.row.id : this.cell.id.rowID;
442444
if (isAddRow) {
443445
this.grid.validation.clear(id);
444446
} else {
445447
this.grid.validation.update(id, rowEditArgs.oldValue);
446448
}
447-
} else if (this.row.getClassName() === IgxEditRow.name) {
449+
} else if (!this.row.isAddRow) {
448450
rowEditArgs = this.grid.gridAPI.update_row(this.row, this.row.newData, event);
449451
nonCancelableArgs = this.rowEditDone(rowEditArgs.oldValue, event);
450452
} else {
@@ -560,7 +562,7 @@ export class IgxRowAddCrudState extends IgxRowCrudState {
560562
* @hidden @internal
561563
*/
562564
public override endRowTransaction(commit: boolean, event?: Event): IGridEditEventArgs | IRowDataCancelableEventArgs {
563-
const isAddRow = this.row && this.row.getClassName() === IgxAddRow.name;
565+
const isAddRow = this.row && this.row.isAddRow;
564566
if (isAddRow) {
565567
this.grid.rowAdded.pipe(first()).subscribe((addRowArgs: IRowDataEventArgs) => {
566568
const rowData = addRowArgs.data;

projects/igniteui-angular/src/lib/grids/common/pipes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ export class IgxGridAddRowPipe implements PipeTransform {
397397
constructor(@Inject(IGX_GRID_BASE) private grid: GridType) { }
398398

399399
public transform(collection: any, isPinned = false, _pipeTrigger: number) {
400-
if (!this.grid.rowEditable || !this.grid.crudService.row || this.grid.crudService.row.getClassName() !== IgxAddRow.name ||
400+
if (!this.grid.rowEditable || !this.grid.crudService.row || !this.grid.crudService.row.isAddRow ||
401401
!this.grid.crudService.addRowParent || isPinned !== this.grid.crudService.addRowParent.isPinned) {
402402
return collection;
403403
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ import { GridResourceStringsEN, IGridResourceStrings } from '../core/i18n/grid-r
6969
import { IgxGridSummaryService } from './summaries/grid-summary.service';
7070
import { IgxSummaryRowComponent } from './summaries/summary-row.component';
7171
import { IgxGridSelectionService } from './selection/selection.service';
72-
import { IgxEditRow, IgxCell, IgxAddRow } from './common/crud.service';
72+
import { IgxEditRow, IgxCell } from './common/crud.service';
7373
import { ICachedViewLoadedEventArgs, IgxTemplateOutletDirective } from '../directives/template-outlet/template_outlet.directive';
7474
import { IgxExcelStyleLoadingValuesTemplateDirective } from './filtering/excel-style/excel-style-search.component';
7575
import { IgxGridColumnResizerComponent } from './resizing/resizer.component';
@@ -3342,7 +3342,7 @@ export abstract class IgxGridBaseDirective implements GridType,
33423342
.map(t => t.newValue));
33433343
}
33443344

3345-
if (this.crudService.row && this.crudService.row.getClassName() === IgxAddRow.name) {
3345+
if (this.crudService.row && this.crudService.row.isAddRow) {
33463346
result.splice(this.crudService.row.index, 0, this.crudService.row.data);
33473347
}
33483348

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IGroupByRecord } from '../data-operations/groupby-record.interface';
2-
import { IgxAddRow, IgxEditRow } from './common/crud.service';
2+
import { IgxEditRow } from './common/crud.service';
33
import { GridSummaryCalculationMode, GridSummaryPosition } from './common/enums';
44
import { IgxGridCell } from './grid-public-cell';
55
import { IgxSummaryResult } from './summaries/grid-summary';
@@ -47,7 +47,7 @@ abstract class BaseRow implements RowType {
4747
*/
4848
public get addRowUI(): boolean {
4949
return !!this.grid.crudService.row &&
50-
this.grid.crudService.row.getClassName() === IgxAddRow.name &&
50+
this.grid.crudService.row.isAddRow &&
5151
this.grid.crudService.row.id === this.key;
5252
}
5353

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@
277277
<div class="igx-banner__message">
278278
<span class="igx-banner__text">
279279
<ng-container
280-
*ngTemplateOutlet="this.crudService.row?.getClassName() === 'IgxAddRow' ? rowAddTextTemplate : rowEditTextTemplate ? rowEditTextTemplate : defaultRowEditText;
281-
context: { $implicit: this.crudService.row?.getClassName() !== 'IgxAddRow' ? rowChangesCount : null }">
280+
*ngTemplateOutlet="this.crudService.row?.isAddRow ? rowAddTextTemplate : rowEditTextTemplate ? rowEditTextTemplate : defaultRowEditText;
281+
context: { $implicit: !this.crudService.row?.isAddRow ? rowChangesCount : null }">
282282
</ng-container>
283283
</span>
284284
</div>

projects/igniteui-angular/src/lib/grids/hierarchical-grid/hierarchical-grid.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@
233233
<div class="igx-banner__message">
234234
<span class="igx-banner__text">
235235
<ng-container
236-
*ngTemplateOutlet="this.crudService.row?.getClassName() === 'IgxAddRow' ? rowAddTextTemplate : resolveRowEditText || defaultRowEditText;
237-
context: { $implicit: this.crudService.row?.getClassName() !== 'IgxAddRow' ? rowChangesCount : null }">
236+
*ngTemplateOutlet="this.crudService.row?.isAddRow ? rowAddTextTemplate : resolveRowEditText || defaultRowEditText;
237+
context: { $implicit: !this.crudService.row?.isAddRow ? rowChangesCount : null }">
238238
</ng-container>
239239
</span>
240240
</div>

projects/igniteui-angular/src/lib/grids/row.directive.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { IgxCheckboxComponent } from '../checkbox/checkbox.component';
2121
import { IgxGridForOfDirective } from '../directives/for-of/for_of.directive';
2222
import { TransactionType } from '../services/transaction/transaction';
2323
import { IgxGridSelectionService } from './selection/selection.service';
24-
import { IgxAddRow, IgxEditRow } from './common/crud.service';
24+
import { IgxEditRow } from './common/crud.service';
2525
import { CellType, ColumnType, GridType, IGX_GRID_BASE } from './common/grid.interface';
2626
import { mergeWith } from 'lodash-es';
2727
import { Subject } from 'rxjs';
@@ -140,7 +140,7 @@ export class IgxRowDirective implements DoCheck, AfterViewInit, OnDestroy {
140140

141141
public get addRowUI(): any {
142142
return !!this.grid.crudService.row &&
143-
this.grid.crudService.row.getClassName() === IgxAddRow.name &&
143+
this.grid.crudService.row.isAddRow &&
144144
this.grid.crudService.row.id === this.key;
145145
}
146146

projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@
210210
<div class="igx-banner__message">
211211
<span class="igx-banner__text">
212212
<ng-container
213-
*ngTemplateOutlet="this.crudService.row?.getClassName() === 'IgxAddRow' ? rowAddTextTemplate : rowEditTextTemplate ? rowEditTextTemplate : defaultRowEditText;
214-
context: { $implicit: this.crudService.row?.getClassName() !== 'IgxAddRow' ? rowChangesCount : null }">
213+
*ngTemplateOutlet="this.crudService.row?.isAddRow ? rowAddTextTemplate : rowEditTextTemplate ? rowEditTextTemplate : defaultRowEditText;
214+
context: { $implicit: !this.crudService.row?.isAddRow? rowChangesCount : null }">
215215
</ng-container>
216216
</span>
217217
</div>

projects/igniteui-angular/src/lib/grids/tree-grid/tree-grid.pipes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ export class IgxTreeGridAddRowPipe implements PipeTransform {
331331
constructor(@Inject(IGX_GRID_BASE) private grid: GridType) { }
332332

333333
public transform(collection: any, isPinned = false, _pipeTrigger: number) {
334-
if (!this.grid.rowEditable || !this.grid.crudService.row || this.grid.crudService.row.getClassName() !== IgxAddRow.name ||
334+
if (!this.grid.rowEditable || !this.grid.crudService.row || !this.grid.crudService.row.isAddRow ||
335335
!this.grid.gridAPI.crudService.addRowParent || isPinned !== this.grid.gridAPI.crudService.addRowParent.isPinned) {
336336
return collection;
337337
}

0 commit comments

Comments
 (0)