[index.cshtml]
<ejs-button id="updateData" content="Update Data"></ejs-button>
<ejs-grid id="Grid" dataSource="ViewBag.DataSource" allowPaging="true" actionBegin="onActionBegin" toolbar="@(new List<string>() {"Add", "Edit", "Update", "Delete" })" >
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Dialog"></e-grid-editSettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" validationRules="@(new { required= true })" textAlign="Right" width="100"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer ID" 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="ShipCity" headerText="Ship City" width="150"></e-grid-column>
</e-grid-columns>
</ejs-grid>
<script id='dialogtemplate' type="text/x-template">
<div id="dialogTemp">
</div>
</script>
<script type="text/javascript">
var editData;
function onActionBegin(args) {
if (args.requestType == "beginEdit" && editData) {
args.rowData = editData; // Update the edited value for edit dialog box
editData = null;
}
}
document.getElementById("updateData").addEventListener("click", function (args) {
var grid = document.getElementById("Grid").ej2_instances[0];
var selectData = grid.getSelectedRecords();
for (var i = 0; i < selectData.length; i++) {
selectData[i].CustomerID = "John";
grid.setRowData(selectData[i].OrderID, selectData[i]);
editData = selectData[i]; // Get the updated value
}
})
</script> |