set editable property for grid column based on another form field

1 Answer 115 Views
Grid
jan
Top achievements
Rank 1
Iron
jan asked on 02 Nov 2021, 03:32 PM

Hi,

I'm trying to set the editable propery of a column depending on an other field of the model.

You have this example in the documentation: kendoGridReactiveEditing

Let's say, if the field 'Discontinued' is false, I would like to disable the editable property of the product name field. For this, I added this to the column definition:


 <kendo-grid-column field="ProductName" title="Product Name" [editable]="formGroup.controls.Discontinued"></kendo-grid-column>

But it says then: 'Error: Cannot read properties of undefined (reading 'controls')'

How can I then access the formgGroup variable in the template?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Accepted
Hetali
Telerik team
answered on 03 Nov 2021, 08:58 PM

Hi Jan,

To set the editable property of the Kendo UI Grid column based on the other column's value, assign a template reference variable to the column and accordingly set it's editable value in the createFormGroup function. For example:

<kendo-grid [kendoGridReactiveEditing]="createFormGroup">
  <kendo-grid-column #productname field="ProductName" title="Product Name">
  </kendo-grid-column>
</kendo-grid>

@ViewChild('productname') public productname;

public createFormGroup(args: any): FormGroup {
  this.productname.editable = args.dataItem.Discontinued? true : false;
}

In this StackBlitz example, the ProductName's editable value depends on the Discontinued column.

I hope this helps. Please let me know if I can further assist you.

Regards,
Hetali
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Grid
Asked by
jan
Top achievements
Rank 1
Iron
Answers by
Hetali
Telerik team
Share this question
or