function endEdit(args) {
var editedRecord = args.data.item;
var treeGridObj = $("#InventoryGrid").data("ejTreeGrid");
var index = treeGridObj.model.updatedRecords.indexOf(args.data);
$.ajax({
type: "POST",
url: '@Url.Content("~/Inventory/UpdateInventory/")',
data: editedRecord,
dataType: "json",
success: function (data) {
var treeGridObj = $("#InventoryGrid").data("ejTreeGrid");
var index = treeGridObj.model.updatedRecords.indexOf(args.data);
treeGridObj.refreshRow(index);
}
});
}
function ActionComplete(args)
{
if (args.requestType==='recordUpdate')
{
var item=args.data.item;
$.ajax({
type:"POST",
//url: "/Inventory/UpdateInventory",
url:'@Url.Content("~/Inventory/UpdateInventory/")',
data: item,
dataType: "json"
});
}else if (args.requestType==='addNewRow') {
addedRecord=args.addedRow;
var treeGridObj=$("#InventoryGrid").data("ejTreeGrid");
var index=treeGridObj.model.updatedRecords.indexOf(args.data);
$.ajax({
type:"POST",
url:'@Url.Content("~/Inventory/UpdateInventory/")',
data:addedRecord,
dataType: "json",
success: function(data){
}
});
}else if (args.requestType==='delete') {
var treeGrid=$("#InventoryGrid").data("ejTreeGrid");
var data=args.data;
var deletedRecord=data.item;
$.ajax({
type:"POST",
url:'@Url.Content("~/Inventory/DeleteInventory/")',
data:deletedRecord,
dataType: "json",
success:function(data){
});
}
});
}
}
Thank you,
Harry
Hi Harry,
We have achieved your requirement “Perform editing operation using Ajax post” with the help of “ActionComplete” event of Grid. Please refer to the code example.
@(Html.EJ().Grid<AjaxEditing.OrdersView>("FlatGrid") .ClientSideEvents(e => { e.ActionComplete("complete"); }) . . . ) <script type="text/javascript"> function complete(args) { if (args.requestType == "save") { $("#FlatGrid").ejWaitingPopup("show"); var val = JSON.stringify(args.data); //Get the Url based on action var path = args.action == "add" ? "../Grid/Insert" : "../Grid/Update" //Ajax post for Insert and Edit $.ajax({ type: "POST", url: path, data: { data: val }, dataType: "json", success: function (data) { $("#FlatGrid").ejWaitingPopup("hide"); } }) } if (args.requestType == "delete") { $("#FlatGrid").ejWaitingPopup("show"); var val = args.data.OrderID; //Ajax Post for Delete $.ajax({ type: "POST", url: "../Grid/Delete", data: {key: val}, dataType: "json", success: function (data) { $("#FlatGrid").ejWaitingPopup("hide"); } }) } } </script> |
We have created a sample that you can download from the below link.
http://www.syncfusion.com/downloads/support/forum/121186/ze/AjaxEditing677411249
Regards,
Saravanan A.