From ae2d29ea6d68175a8334fa58496d739da5eb1ba1 Mon Sep 17 00:00:00 2001 From: ViktorSlavov Date: Thu, 13 Jun 2019 14:46:15 +0300 Subject: [PATCH] fix(grid): move row edit warning to crudService.beginRowEdit, #5010 --- .../src/lib/core/grid-selection.ts | 3 +++ .../src/lib/grids/grid-base.component.ts | 27 ++++--------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/projects/igniteui-angular/src/lib/core/grid-selection.ts b/projects/igniteui-angular/src/lib/core/grid-selection.ts index ebea5a5ee3c..136ce4b94dc 100644 --- a/projects/igniteui-angular/src/lib/core/grid-selection.ts +++ b/projects/igniteui-angular/src/lib/core/grid-selection.ts @@ -126,6 +126,9 @@ export class IgxGridCRUDService { } beginRowEdit() { + if (this.grid.rowEditable && (this.grid.primaryKey === undefined || this.grid.primaryKey === null)) { + console.warn('The grid must have a `primaryKey` specified when using `rowEditable`!'); + } this.row = this.createRow(this.cell); const args = { rowID: this.row.id, diff --git a/projects/igniteui-angular/src/lib/grids/grid-base.component.ts b/projects/igniteui-angular/src/lib/grids/grid-base.component.ts index d53574156eb..b98155c1ff9 100644 --- a/projects/igniteui-angular/src/lib/grids/grid-base.component.ts +++ b/projects/igniteui-angular/src/lib/grids/grid-base.component.ts @@ -208,7 +208,7 @@ export interface IRowDragEndEventArgs { export interface IRowDragStartEventArgs extends CancelableEventArgs { owner: IgxDragDirective; dragData: IgxRowComponent; -} + } export enum GridSummaryPosition { top = 'top', @@ -247,7 +247,6 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements private _locale = null; private _observer: MutationObserver; private _destroyed = false; - private _primaryKey = null; private overlayIDs = []; /** * An accessor that sets the resource strings. @@ -605,7 +604,6 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements set rowEditable(val: boolean) { this._rowEditable = val; if (this.gridAPI.grid) { - this.checkEditKey(val); this.refreshGridState(); } } @@ -759,16 +757,8 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements */ @WatchChanges() @Input() - public set primaryKey(val: any) { - this._primaryKey = val; - if (this.gridAPI.grid) { - this.checkEditKey(this._rowEditable); - } - } + public primaryKey; - public get primaryKey(): any { - return this._primaryKey; - } /** * An @Input property that sets the message displayed when there are no records. * ```html @@ -2595,12 +2585,6 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements this.hideOverlays(); } - private checkEditKey(val: boolean): void { - if (val && (this.primaryKey === undefined || this.primaryKey === null)) { - console.warn('The grid must have a `primaryKey` specified when using `rowEditable`!'); - } - } - /** * @hidden * @internal @@ -2716,7 +2700,6 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements this.calcWidth = this._width && this._width.indexOf('%') === -1 ? parseInt(this._width, 10) : 0; this.shouldGenerate = this.autoGenerate; this._scrollWidth = this.getScrollWidth(); - this.checkEditKey(this._rowEditable); } protected setupColumns() { @@ -3411,7 +3394,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements this._moveColumns(column, dropTarget, position); this.cdr.detectChanges(); if (this.hasColumnLayouts) { - this.columns.filter(x => x.columnLayout).forEach(x => x.populateVisibleIndexes()); + this.columns.filter(x => x.columnLayout).forEach( x => x.populateVisibleIndexes()); } const args = { @@ -4911,13 +4894,13 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements && this.navigation.isColumnLeftFullyVisible(visibleColIndex))) { if (this.navigation.shouldPerformVerticalScroll(rowIndex, visibleColIndex)) { this.navigation.performVerticalScrollToCell(rowIndex, visibleColIndex, - () => { this.executeCallback(rowIndex, visibleColIndex, cb); }); + () => { this.executeCallback(rowIndex, visibleColIndex, cb); } ); } else { this.executeCallback(rowIndex, visibleColIndex, cb); } } else { this.navigation.performHorizontalScrollToCell(rowIndex, visibleColIndex, false, - () => { this.executeCallback(rowIndex, visibleColIndex, cb); }); + () => { this.executeCallback(rowIndex, visibleColIndex, cb); }); } }