@(Html.EJ().Grid<object>("Editing")
.Datasource((IEnumerable<object>)ViewBag.datasource)
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Batch); })
--------
.ClientSideEvents(eve => eve.QueryCellInfo("calculate"))
.Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(90).Add();
col.Field("CustomerID").HeaderText("Customer ID").Width(90).ValidationRules(v => v.AddRule("required", true).AddRule("minlength", 3)).Add();
col.Field("EmployeeID").HeaderText("Employee ID").EditType(EditingType.DropdownEdit).TextAlign(TextAlign.Right).Width(80).Add();
col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(80)
.EditType(EditingType.NumericEdit).Format("{0:C}").Add();
}))
<script type="text/javascript">
function calculate(args) {
if (args.column.field == "Freight") {
var y = args.data.EmployeeID * args.data.OrderID;
$(args.cell).text(y);
args.data.Freight = y; // update the column value in the dataSource.
}
}
</script> |