@(Html.EJ().Grid<OrdersView>("Grid")
.AllowPaging()
.Datasource(ds =>
{
ds.Json(ViewBag.datasource);
})
.EditSettings(edit =>
{
edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Batch);
})
.Columns(col =>
{
. . .
col.Field("CDCRegionId").Width(120).AllowEditing(true).HeaderText("Region").ForeignKeyField("CDCRegionId").ForeignKeyValue("CDCRegion").DataSource((IEnumerable<Object>)ViewBag.Region).ValidationRules(v => v.AddRule("required", true)).Add();
. . .
})
.ClientSideEvents(events => events.Load("load").CellEdit("cellEdit").BeforeBatchSave("beforeSave"))
)
<script>
function load(args) {
//check edited rows
this.model.isrowEdited = [];
this.model.columns[2].editParams = $.extend(true, {}, {
change: function (e) {
this.element.closest(".e-grid").ejWaitingPopup("show");
$.ajax({
url: 'GetData',
type: 'POST',
data: { "ID": e.text },
success: ej.proxy(function (data) {
this.element.closest(".e-grid").ejWaitingPopup("hide");
var gridObj = this.element.closest(".e-grid").ejGrid("instance");
var inx = gridObj.getIndexByRow(this.element.closest("tr[data-role='row']"));
//push edited rows
gridObj.model.isrowEdited.push(inx);
//set value to the next dropdown column
gridObj.setCellValue(inx, "CustomerID", data.selectedItem.text);
gridObj.model.columns[3].dataSource = data.data;
}, this)
})
}
});
}
<script> |