Articles in this section
Category / Section

Cell edit using Multiline Textbox control in Angular Grid

1 min read

By default, the TextBox control will be used as a default editor control for the string column in Angular Grid. You can customize the editor control using Multiline Textbox by rendering it as a custom component in the Grid edit form.

You can use the cellEditTemplate feature of Grid to render the Multiline TextBox component in the Grid edit form. The cell edit template is used to add a custom component for a particular column by invoking the create, write, read, and destroy functions.

this.dpParams = {
     create: () => {
          this.elemContent = document.createElement('textarea');
          return this.elemContent;
      },
      read: () => {
           return this.textEditor.value;
      },
      destroy: () => {
          this.textEditor.destroy();
      },
      write: (args) => {
           this.textEditor = new TextBox({
              multiline: true,
              value: args.rowData[args.column.field],
              floatLabelType: 'Auto'
        });
        this.textEditor.appendTo(this.elemContent);
      },
    };

 

Using the valueAccessor feature of Grid, you can split the value into multiple lines in the Grid column.

Note:

When editing a particular cell in the Grid, you can prevent the ENTER key’s functionality using the created event in the Grid.

 

  public valueAccessor = (field: string, data1: object, column: object) => {
    var value = data[field];
    if (value != undefined) {
        return value.split('\n').join('<br>');
    } else {
        return '';
    }  
};
  created(args) {
    this.grid.keyConfigs.enter = '';
  }

 

Output

Before editing in Angular Grid

 

After editing in Angular Grid

 

You can find the sample here:

Angular Sample

 

Documentation

https://ej2.syncfusion.com/angular/documentation/grid/edit/#cell-edit-template

https://ej2.syncfusion.com/angular/documentation/textbox/multiline/

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied