New to Kendo UI for Angular? Start a free 30-day trial

Angular Data Grid Built-In Editing Directives

The editing directives simplify the implementation of the editing operations. You can easily create common editing scenarios with less code and maintain clean and readable configurations.

The editing directives handle the necessary Grid events internally—this helps you cut down the repetitive boilerplate code. As a result, the component code is cleaner, shorter, and more concise.

The Data Grid offers two editing modes represented by three built-in directives:

By default, the built-in editing directives automatically modify the data that is passed to the Grid. You may want to show a Confirmation Dialog before removing a record or completely customize the editing behavior by specifying a Custom Editing Service.

Inline Editing

The inline editing of the Grid toggles the entire Grid row into edit mode. To perform the necessary CRUD (create, remove, updated, and delete) operations, click the corresponding buttons.

Based on the used Angular Forms, the Grid exposes two built-in editing directives:

Reactive Editing Directive

The kendoGridReactiveEditing directive simplifies the setup when implementing an editable Grid with Reactive Forms. To configure the Grid with the ReactiveEditingDirective:

  1. Provide a callback which returns the FormGroup for the edited item.

    <kendo-grid [kendoGridReactiveEditing]="createFormGroup">
        ...
    </kendo-grid>
  2. In the custom createFormGroup callback, create and return the FormGroup for the row model. For the newly added rows, create a new instance of the model.

    public formGroup: FormGroup;
    constructor(private formBuilder: FormBuilder) {}
    
    public createFormGroup = (args: any): FormGroup => {
        const item = args.isNew ? new Product() : args.dataItem;
    
        this.formGroup = this.formBuilder.group({
            ProductID: item.ProductID,
            ProductName: [item.ProductName],
            ...
        });
    
        return this.formGroup;
    };
  3. Use the command directives to create buttons that automatically perform the desired CRUD operations. For more details, refer to the Command Column Directives section.

The following example demonstrates the kendoGridReactiveEditing directive in action.

Example
View Source
Change Theme:

Template Editing Directive

The kendoGridTemplateEditing directive simplifies the setup when implementing an editable Grid with Template-Driven Forms. To configure the Grid with the TemplateEditingDirective:

  1. Use the EditTemplateDirective of the Grid to display any custom control when the row is in edit mode. Bind the ngModel directive of the custom control to the corresponding value by using the dataItem field provided by the template context.

    <kendo-grid-column field="ProductName" title="Product Name">
        <ng-template kendoGridEditTemplate let-dataItem="dataItem">
        <kendo-textbox
            [(ngModel)]="dataItem.ProductName"
            name="ProductName"
            required
        ></kendo-textbox>
        </ng-template>
    </kendo-grid-column>
  2. Provide a function that creates a new instance of the edited model.

    <form novalidate #myForm="ngForm">
        <kendo-grid [kendoGridTemplateEditing]="createNewProduct">
        ...
        </kendo-grid>
    </form>
    export class Product {
        public ProductID: number;
        public ProductName = '';
        ...
    }
    
    public createNewProduct(): Product {
        return new Product();
    }
  3. Use the command directives to create buttons that automatically perform the desired CRUD operations. For more details, refer to the Command Column Directives section.

The following example demonstrates the kendoGridTemplateEditing directive in action.

Example
View Source
Change Theme:

In-Cell Editing

The kendoGridInCellEditing directive simplifies the setup when implementing an in-cell editable Grid with Reactive Forms. To configure the Grid with the InCellEditingDirective:

  1. Provide a callback which returns the FormGroup for the edited item.

    <kendo-grid [kendoGridInCellEditing]="createFormGroup">
        ...
    </kendo-grid>
  2. In the custom createFormGroup callback, create and return the FormGroup for the row model. For the newly added rows, create a new instance of the model.

    public formGroup: FormGroup;
    constructor(private formBuilder: FormBuilder) {}
    
    public createFormGroup = (args: any): FormGroup => {
        const item = args.isNew ? new Product() : args.dataItem;
    
        this.formGroup = this.formBuilder.group({
            ProductID: item.ProductID,
            ProductName: [item.ProductName],
            /*...*/
        });
    
        return this.formGroup;
    };
  3. Use the command directives to create buttons that automatically perform the desired CRUD operations. For more details, refer to the Command Column Directives section.

If you want to disable the default behavior for specific non-focusable elements, check the article on how to disable the click handler for specific elements.

The following example demonstrates the kendoGridInCellEditing directive in action.

Example
View Source
Change Theme:

Command Column Directives

The command directives (kendoGridEditCommand, kendoGridRemoveCommand, and others) encapsulate the logic behind each editing operation. They can be applied to any button element rendered inside the CommandColumnComponent and trigger the corresponding Grid events allowing further customizations.

<kendo-grid-command-column title="Commands">
    <ng-template kendoGridCellTemplate>
        <button kendoGridEditCommand>Edit</button>
        ...
    </ng-template>
</kendo-grid-command-column>

The following table lists the available built-in command directives.

Command DirectiveDescription
AddCommandDirectiveDirective for adding a new item to the Grid. Triggers the add event. Can be used within a Toolbar template or CommandColumnComponent
EditCommandDirectiveDirective for editing a row. Triggers the edit event.
RemoveCommandDirectiveDirective for removing a records. Triggers the remove event.
SaveCommandDirectiveDirective for saving the changes. Triggers the save event.
CancelCommandDirectiveDirective for canceling the changes. Triggers the cancel event.

Confirmation Dialog on Row Removal

Using any of the built-in editing directives in your project allows you to display a built-in confirmation dialog when the user is about to remove a row.

To show the confirmation dialog, set a function to the removeConfirmation option. The function is expected to return a Boolean value which will indicate if the record will be removed.

If the function returns an Observable or a Promise, resolve it with a Boolean value.

The following example demonstrates how to display a confirmation dialog before removing a row.

Example
View Source
Change Theme:

Custom Editing Service

Each directive exposes a built-in editService option which allows you to use a custom editing service.

By default, the built-in editing directives modify the data that is passed to the Grid automatically. You can customize this behavior by implementing a custom service through the editService property. The custom service handles the create, update, and remove data operations and implements the EditService interface.

If the Grid is not bound to a plain array, specify EditService.

The following example demonstrates how to implement a custom editing service.

Example
View Source
Change Theme: