Articles in this section
Category / Section

Cell edit using Multiline Textbox in JavaScript Grid

1 min read

By default, the TextBox control will be used as a default editor control for the string column in Javascript 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.

edit: {
    create: function () {
        elemContent = document.createElement('textarea');
        return elemContent;
   },
   destroy: function () {
       textEditor.destroy();
   },
   read: function () {
       return textEditor.value;
   },
   write: function (args) {
       textEditor = new TextBox({
       multiline: true,
       value: args.rowData[args.column.field],
       floatLabelType: 'Auto'
    });
    textEditor.appendTo(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.

 

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

 

Output

Before editing in JavaScript Grid

 

After editing in JavaScript Grid

 

You can find the sample here:

Javascript Sample

 

Documentation

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

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

 

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