Skip to content

Commit 5390650

Browse files
authored
Merge branch 'master' into mkirova/fix-5102-master
2 parents a5e1b37 + 841cb65 commit 5390650

File tree

3 files changed

+76
-20
lines changed

3 files changed

+76
-20
lines changed

projects/igniteui-angular/src/lib/grids/column.component.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,36 @@ export class IgxColumnComponent implements AfterContentInit {
117117
}
118118
}
119119
/**
120-
* Sets/gets whether the column is editable.
120+
* Gets whether the column is editable.
121121
* Default value is `false`.
122122
* ```typescript
123123
* let isEditable = this.column.editable;
124124
* ```
125+
* @memberof IgxColumnComponent
126+
*/
127+
@Input()
128+
get editable(): boolean {
129+
let result = false;
130+
if (this._editable !== undefined) {
131+
result = this._editable;
132+
} else {
133+
result = this.grid && this.grid.rowEditable && this.field !== this.grid.primaryKey;
134+
}
135+
return result;
136+
}
137+
/**
138+
* Sets whether the column is editable.
139+
* ```typescript
140+
* this.column.editable = true;
141+
* ```
125142
* ```html
126143
* <igx-column [editable] = "true"></igx-column>
127144
* ```
128145
* @memberof IgxColumnComponent
129146
*/
130-
@Input()
131-
public editable = null;
147+
set editable(editable: boolean) {
148+
this._editable = editable;
149+
}
132150
/**
133151
* Sets/gets whether the column is filterable.
134152
* Default value is `true`.
@@ -1063,6 +1081,10 @@ export class IgxColumnComponent implements AfterContentInit {
10631081
*@hidden
10641082
*/
10651083
protected _hasSummary = false;
1084+
/**
1085+
* @hidden
1086+
*/
1087+
protected _editable: boolean;
10661088
/**
10671089
*@hidden
10681090
*/

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4517,7 +4517,6 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
45174517
collection.forEach((column: IgxColumnComponent) => {
45184518
column.grid = this;
45194519
column.defaultWidth = this.columnWidth;
4520-
this.setColumnEditState(column);
45214520

45224521
if (cb) {
45234522
cb(column);
@@ -4533,14 +4532,6 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
45334532
}
45344533
}
45354534

4536-
private setColumnEditState(column: IgxColumnComponent) {
4537-
// When rowEditable is true, then all columns, with defined field, excluding priamaryKey, are set to editable by default.
4538-
if (this.rowEditable && column.editable === null &&
4539-
column.field && column.field !== this.primaryKey) {
4540-
column.editable = this.rowEditable;
4541-
}
4542-
}
4543-
45444535
/**
45454536
* @hidden
45464537
*/

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

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,7 @@ describe('IgxGrid Component Tests', () => {
16401640
beforeEach(async(() => {
16411641
TestBed.configureTestingModule({
16421642
declarations: [
1643+
IgxGridTestComponent,
16431644
IgxBasicGridRowEditingComponent,
16441645
IgxGridRowEditingComponent,
16451646
IgxGridRowEditingWithoutEditableColumnsComponent,
@@ -3496,19 +3497,61 @@ describe('IgxGrid Component Tests', () => {
34963497
});
34973498

34983499
describe('Row Editing - Column editable property', () => {
3499-
it('Default column editable value is true, when row editing is enabled', fakeAsync(() => {
3500+
it('Default column editable value is correct, when row editing is enabled', fakeAsync(() => {
35003501
const fixture = TestBed.createComponent(IgxGridRowEditingWithoutEditableColumnsComponent);
35013502
fixture.detectChanges();
3502-
tick(16);
3503+
tick();
35033504

35043505
const grid = fixture.componentInstance.grid;
35053506

3506-
const columns: IgxColumnComponent[] = grid.columnList.toArray();
3507-
expect(columns[0].editable).toBeFalsy();
3508-
expect(columns[1].editable).toBeFalsy();
3509-
expect(columns[2].editable).toBeTruthy();
3510-
expect(columns[3].editable).toBeTruthy();
3511-
expect(columns[4].editable).toBeFalsy();
3507+
let columns: IgxColumnComponent[] = grid.columnList.toArray();
3508+
expect(columns[0].editable).toBeTruthy(); // column.editable not set
3509+
expect(columns[1].editable).toBeFalsy(); // column.editable not set. Primary column
3510+
expect(columns[2].editable).toBeTruthy(); // column.editable set to true
3511+
expect(columns[3].editable).toBeTruthy(); // column.editable not set
3512+
expect(columns[4].editable).toBeFalsy(); // column.editable set to false
3513+
3514+
grid.rowEditable = false;
3515+
columns = grid.columnList.toArray();
3516+
expect(columns[0].editable).toBeFalsy(); // column.editable not set
3517+
expect(columns[1].editable).toBeFalsy(); // column.editable not set. Primary column
3518+
expect(columns[2].editable).toBeTruthy(); // column.editable set to true
3519+
expect(columns[3].editable).toBeFalsy(); // column.editable not set
3520+
expect(columns[4].editable).toBeFalsy(); // column.editable set to false
3521+
3522+
grid.rowEditable = true;
3523+
columns = grid.columnList.toArray();
3524+
expect(columns[0].editable).toBeTruthy(); // column.editable not set
3525+
expect(columns[1].editable).toBeFalsy(); // column.editable not set. Primary column
3526+
expect(columns[2].editable).toBeTruthy(); // column.editable set to true
3527+
expect(columns[3].editable).toBeTruthy(); // column.editable not set
3528+
expect(columns[4].editable).toBeFalsy(); // column.editable set to false
3529+
}));
3530+
3531+
it(`Default column editable value is correct, when row edititng is disabled`, fakeAsync(() => {
3532+
const fixture = TestBed.createComponent(IgxGridTestComponent);
3533+
fixture.componentInstance.columns.push({ field: 'ID', header: 'ID', dataType: 'number', width: null, hasSummary: false });
3534+
fixture.componentInstance.data = [
3535+
{ ID: 0, index: 0, value: 0},
3536+
{ ID: 1, index: 1, value: 1},
3537+
{ ID: 2, index: 2, value: 2},
3538+
];
3539+
const grid = fixture.componentInstance.grid;
3540+
grid.primaryKey = 'ID';
3541+
3542+
fixture.detectChanges();
3543+
tick();
3544+
3545+
let columns: IgxColumnComponent[] = grid.columnList.toArray();
3546+
expect(columns[0].editable).toBeFalsy(); // column.editable not set
3547+
expect(columns[1].editable).toBeFalsy(); // column.editable not set
3548+
expect(columns[2].editable).toBeFalsy(); // column.editable not set. Primary column
3549+
3550+
grid.rowEditable = true;
3551+
columns = grid.columnList.toArray();
3552+
expect(columns[0].editable).toBeTruthy(); // column.editable not set
3553+
expect(columns[1].editable).toBeTruthy(); // column.editable not set
3554+
expect(columns[2].editable).toBeFalsy(); // column.editable not set. Primary column
35123555
}));
35133556
});
35143557

0 commit comments

Comments
 (0)