<ejs-grid id="Grid" dataSource="@ViewBag.datasource" height="315" allowPaging="true" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })">
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true"></e-grid-editSettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="100"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer ID" edit="@(new {create = "create", read = "read", destroy = "destroy", write = "write"})" type="string" width="120"></e-grid-column>
<e-grid-column field="Freight" headerText="Freight" textAlign="Right" format="C2" editType="numericedit" width="120"></e-grid-column>
<e-grid-column field="ShipCountry" headerText="Ship Country" width="150"></e-grid-column>
</e-grid-columns>
</ejs-grid> |
<script>
var elem;
var drpObj;
function create(args) {
elem = document.createElement('input');
return elem;
}
function write(args) {
var grid = document.getElementById('Grid')["ej2_instances"][0];
var data = grid.dataSource;
drpObj = new ej.dropdowns.DropDownList({
value: args.rowData[args.column.field],
dataSource: data,
fields: { text: 'CustomerID', value: 'CustomerID' },
sortOrder: 'None'
});
drpObj.appendTo(elem);
}
function destroy() {
drpObj.destroy();
}
function read(args) {
return drpObj.value;
}
</script> |