Articles in this section
Category / Section

How to cell edit template using Textbox in React Grid?

5 mins read

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

dpParams = {
    create: () => {
        this.elemContent = document.createElement('textarea');
        return this.elemContent;
    },
    destroy: () => {
        this.textEditor.destroy();
    },
    read: () => {
        return this.textEditor.value;
    },
    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.

 

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

 

Output

Before editing in React Grid

 

After editing in React Grid

 

You can find the sample here:

React Sample

 

Documentation

https://ej2.syncfusion.com/react/documentation/grid/editing/template-editing

 

Conclusion

I hope you enjoyed learning about how to cell edit template using Multiline Textbox in React Grid.

You can refer to our React Grid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our React Grid example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

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