@Html.EJS().Grid("EditParam").DataSource((IEnumerable<object>)ViewBag.datasource).Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("120").ValidationRules(new { required = "true" }).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("ShipCountry").HeaderText("Ship Country").EditType("dropdownedit").Width("150").Add();
col.Field("CustomerID").HeaderText("Customer Name").AllowEditing(false).Width("150").Add();
col.Field("Freight").HeaderText("Freight").Width("120").AllowEditing(false).EditType("numericedit").Format("C2").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
}).AllowPaging().ActionComplete("ActionComplete").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>
function ActionComplete(args) {
if (args.requestType == 'beginEdit') {
// get the shipcountry dropdown element in the grid form
var ddobj = args.form.elements.ShipCountry[1].ej2_instances[0];
// bind the change event to the dropdown
ddobj.change = function (args) {
// get the grid instance
var grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0];
// get the freight column input element
var freightinput = grid.editModule.formObj.element.elements.EditParamFreight; // editparam + column field name
// get the customerID column input element
var customeridinput = grid.editModule.formObj.element.elements.EditParamCustomerID; // editparam + column field name
// change the value of customerID and freight column based on dropdown select value
switch (args.value) {
case 'Denmark': // dropdown select value
freightinput.ej2_instances[0].value = 2; // changing freight column value
customeridinput.value = 'ALFKI'; // changing customerID column value
break;
case 'Brazil':
freightinput.ej2_instances[0].value = 4;
customeridinput.value = 'ANATR';
break;
case 'Germany':
freightinput.ej2_instances[0].value = 6;
customeridinput.value = 'ANTON';
break;
default :
freightinput.ej2_instances[0].value = 8;
customeridinput.value = 'BLONP';
break;
}
}
}
}
</script> |