New to Kendo UI for AngularStart a free 30-day trial

Prevent Editing for Specific Fields

The Grid allows you to restrict users from editing specific fields. This is suitable when you want some columns to stay the same, while still letting users edit the rest of the information.

Change Theme
Theme
Loading ...

To prevent editing specific cells, you can use any of the following approaches:

  • Disable editing for selected fields, such as IDs or company names, by setting the built-in editable option of the respective column(s) to false.

    html
    <kendo-grid ... >
        <kendo-grid-column field="ProductID" [editable]="false"></kendo-grid-column>
        ...
    </kendo-grid>
  • Omit the field(s) declaration in the FormGroup.

    ts
    public createFormGroup(dataItem: any): FormGroup {
        return this.formBuilder.group({
            // 'ProductID': dataItem.ProductID,
            'UnitPrice': dataItem.UnitPrice,
            'UnitsInStock': [dataItem.UnitsInStock, Validators.compose([Validators.required, Validators.pattern('^[0-9]{1,3}')])],
            'Discontinued': dataItem.Discontinued
        });
    }
  • Skip the editCell method invocation in the cellClick event handler.

    ts
    public cellClickHandler({ sender, column, rowIndex, columnIndex, dataItem, isEdited }) {
        if (!isReadOnly(column.field)) {
            sender.editCell(rowIndex, columnIndex, this.createFormGroup(dataItem));
        }
    }

The following example demonstrates the complete implementation of the cellClick event-handler approach.

Change Theme
Theme
Loading ...
In this article
Suggested Links
Not finding the help you need?
Contact Support