@{
var DropDownList = new Syncfusion.EJ2.DropDowns.DropDownList()
{
Change = "Changed",
};
}
<div>
<ejs-grid id="Grid" dataSource="ViewBag.data" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })" allowPaging="true">
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Dialog" newRowPosition="Top"></e-grid-editSettings>
<e-grid-pagesettings pageCount="5"></e-grid-pagesettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" width="140"></e-grid-column>
<e-grid-column field="CustomerID" editType="dropdownedit" edit="@(new {@params = DropDownList})" headerText="Customer Name" width="150"></e-grid-column>
</e-grid-columns>
</ejs-grid>
</div>
<script>
function Changed(args) {
console.log(args);
}
</script> |
function Changed(args) {
if (typeof args != 'undefined') {
data = args.itemData;
if (typeof data != 'undefined') {
var grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0];
var cols = grid.columns; //getting the grid columns
for (var i = 0; i < cols.length; i++) {
if (cols[i].field === 'OrderID' && cols[i].allowEditing) { //checking the field whether read only or not
document.querySelector("#" + grid.element.id + cols[i].field).value = 10;
}
if (cols[i].field === 'CustomerID' && cols[i].allowEditing) {
document.querySelector("#" + grid.element.id + cols[i].field).value = "Updated";
}
if (cols[i].field === 'Freight' && cols[i].allowEditing) {
document.querySelector("#" + grid.element.id + cols[i].field).value = 45.67;
}
}
}
}
}
|