Cell editing using Multiline Textbox Control in ASP.NET Core Grid
By default, the TextBox control will be used as a default editor control for the string column in ASP Core 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.
Using the valueAccessor feature of Grid, you can split the value into multiple lines in the Grid column.
When editing a particular cell in the Grid, you can prevent the ENTER key’s functionality using the created event in the Grid.
@{ var valueAccessor = "valueAccessorFn"; } <ejs-grid id="Grid" dataSource="@ViewBag.DataSource" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })" created="created"> <e-grid-editsettings allowEditing="true" allowAdding="true" allowDeleting="true"></e-grid-editsettings> <e-grid-columns> <e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" width="100" textAlign="Right"></e-grid-column> <e-grid-column field="Freight" format='C2' headerText="Freight" width="120"></e-grid-column> <e-grid-column field="ShipCity" headerText="Ship City" width="150" disableHtmlEncode="false" valueAccessor="valueAccessor" edit="@(new {create = "create", read = "read", destroy = "destroy", write = "write"})" ></e-grid-column> </e-grid-columns> </ejs-grid> <script> var textEditor; var elemContent; function create(args) { elemContent = document.createElement('textarea'); return elemContent; } function write(args) { textEditor = new ej.inputs.TextBox({ multiline: true, value: args.rowData[args.column.field], floatLabelType: 'Auto' }); textEditor.appendTo(elemContent); } function destroy() { textEditor.destroy(); } function read(args) { return textEditor.value; } function created(args) { document.getElementById('Grid').ej2_instances[0].keyConfigs.enter = ''; } function valueAccessorFn(field, data, column){ var value = data[field]; if (value !== undefined) { return value.split("\n").join("<br>"); } else { return ""; } } </script>
Output
You can find the sample here:
Documentation
https://ej2.syncfusion.com/aspnetcore/documentation/grid/edit/#cell-edit-template
https://ej2.syncfusion.com/aspnetcore/documentation/textbox/multiline/