[Index.cshtml]
<ejs-grid id="Grid" dataSource="ViewBag.dataSource" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })" allowPaging="true" height="300">
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true"></e-grid-editSettings>
<e-grid-columns>
<e-grid-column field="OrderID" width="110" isPrimaryKey=true></e-grid-column>
<e-grid-column field="CustomerID" headerText="CustomerID" width="110"></e-grid-column>
<e-grid-column field="ShipCountry" headerText="ShipCountry" edit="@(new { create = "create", read = "read", destroy = "destroy", write = "write" })" width="110">
</e-grid-column>
<e-grid-column field="ShipCity" width="110">
</e-grid-column>
</e-grid-columns>
</ejs-grid>
<script>
var countryElem;
var countryObj;
function read() {
return countryObj.text;
}
function destroy() {
countryObj.destroy();
}
function write(args) {
countryObj = new ej.dropdowns.DropDownList({
dataSource: @Html.Raw(Json.Serialize(ViewBag.dataSource)),
fields: { value: 'ShipCountry', text: 'ShipCountry' },
placeholder: 'Select a country',
floatLabelType: 'Never',
value: args.rowData[args.column.field]
});
countryObj.appendTo(countryElem);
}
</script> |