@(Html.EJ().Grid<OrdersView>("Editing")
.Datasource(ds => ds.URL("/Grid/UrlDataSource").UpdateURL("/Grid/Update").InsertURL("/Grid/Insert").RemoveURL("NormalDelete").Adaptor(AdaptorType.UrlAdaptor))
.ClientSideEvents(e => e.ActionBegin("begin").QueryCellInfo("query").ActionComplete("complete").Load("onLoad"))
.Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(90).Add();
col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(80).Add();
col.Field("ShipCity").HeaderText("ShipName").Width(150).AllowEditing(true).Add();
col.Field("Verified").HeaderText("Verified").Width(90).AllowEditing(false).Add();
})
)
<script id="template" type="text/template">
<table cellspacing="10">
<tr>
<
<td>Languages</td>
<td>
<select id="Languages" name="Languages"></select>
</td>
</tr>
</table>
</script>
<script>
var drpData = [];
function query(args) {
if (args.column.field == "Language") {
args.cell.innerText = ej.dataUtil.distinct(args.data.Languages, "Lanugages");
}
}
//Actionbegin assigning the newly update value
function begin(args) {
if (args.requestType == "save") {
debugger
args.data.Languages = drpData;
}
}
function complete(args) {
if (args.requestType == "add" || args.requestType == "beginedit") {
var dropData = @Html.Raw(Json.Encode(ViewBag.data));
$("#Languages").ejDropDownList({
width: "100%",
change: function (args) {
var txt = args.text.split(","), vals = args.model.value.split(",");
for (var t = 0; t < txt.length; t++) {
//creating a list of objects for newly saving records
var obj = {};
ej.createObject("Lanugages", txt[t], obj);
ej.createObject("ID", ej.parseInt(vals[t]), obj);
drpData.push(obj);
}
},
multiSelectMode: ej.MultiSelectMode.Delimiter,
showCheckbox: true,
dataSource: dropData,
text: ej.dataUtil.distinct(dropData, "Lanugages").toString(),
fields: { text: "Lanugages", value: "ID" },
});
}
}
</script>
<script>
//Custom Adaptor to customize the existing Adaptor
var customAdaptor = new ej.UrlAdaptor().extend({
processResponse: function (data, ds, query, xhr, request, changes) {
//you can manipulate records as per items selected from multiselect dropdown
return this.base.processResponse.apply(this, [data, ds, query, xhr, request, changes]);
}
});
function onLoad(args) {
this.model.dataSource.adaptor = new customAdaptor();
}
|