|
@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.DataSource).Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).ValidationRules(new { required = "true"}).Add();
col.Field("ShipAddress").HeaderText("Ship Address"). Edit(new { create = "create", read = "read", destroy = "destroy", write = "write" }).Width("150").Add();
}).AllowPaging().EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Normal); }).Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render()
<script>
var elem;
var tObj;
function create(args) {
elem = document.createElement('input');
return elem;
}
function write(args) {
// create a multiline textbox control
tObj = new ej.inputs.TextBox({
placeholder: 'Enter your address',
multiline : true, // enable multiline feature support
value: args.rowData[args.column.field] // bind the column value to the textbox
});
tObj.appendTo(elem);
}
function destroy() {
tObj.destroy();
}
function read(args) {
// return the textbox value to the grid
return tObj.value;
}
</script> |
|
[index.cshtml]
@Html.EJS().Grid("Grid").DataSource(dataManager => { dataManager.Url("/Home/UrlDatasource").InsertUrl("/Home/Insert").UpdateUrl("/Home/Update").RemoveUrl("/Home/Remove").Adaptor("UrlAdaptor"); }).Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).ValidationRules(new { required = "true"}).Add();
col.Field("ShipAddress").HeaderText("Ship Address").Edit(new { create = "createMemo", read = "readMemo", destroy = "destroyMemo", write = "writeMemo" }).Width("150").Add();
}).AllowPaging().EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Normal); }).Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render()
<script>
var elemMultiLine;
var tMultiLineObj;
function createMemo(args) {
elemMultiLine = document.createElement('input');
return elemMultiLine;
}
function writeMemo(args) {
var grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0];
// get the column index
var index = grid.getColumnIndexByField(args.column.field);
console.log(index);
// create a multiline textbox control
tMultiLineObj = new ej.inputs.TextBox({
placeholder: 'Description',
multiline: true, // enable multiline feature support
value: args.rowData[args.column.field],// bind the column value to the textbox
created: function () {
this.element.setAttribute("e-mappinguid", "grid-column" + index);
}
});
tMultiLineObj.appendTo(elemMultiLine);
}
function destroyMemo() {
tMultiLineObj.destroy();
}
function readMemo(args) {
// return the textbox value to the grid
return tMultiLineObj.value;
}
</script>
|