Hello, i am trying to save every SecondChildGrid edited row with external button, how can i do that?
var SecondChild = new Syncfusion.EJ2.Grids.Grid()
{
DataSource = new DataManager()
{
Json =Model.salesOrderLines,
BatchUrl = Url.Action("/Sales/Update"),
Adaptor = "RemoteSaveAdaptor"
},
Id = "SecondChildGrid",
QueryString = "orderLine",
EditSettings = new Syncfusion.EJ2.Grids.GridEditSettings()
{
AllowEditing = true,
Mode = Syncfusion.EJ2.Grids.EditMode.Batch,
ShowConfirmDialog = false
},
Load = "OnLoadChild",
Columns = new List
new Syncfusion.EJ2.Grids.GridColumn(){ Field="orderLine",Visible=false,Width="80",AllowEditing=false, HeaderText="OrderLine",TextAlign=Syncfusion.EJ2.Grids.TextAlign.Center },
new Syncfusion.EJ2.Grids.GridColumn(){ Field="objectID",Width="80",AllowEditing=false, HeaderText="ObjectID",TextAlign=Syncfusion.EJ2.Grids.TextAlign.Center },
new Syncfusion.EJ2.Grids.GridColumn(){ Field="objectName",Width="80",AllowEditing=false, HeaderText="ObjectName", Format="C2", TextAlign=Syncfusion.EJ2.Grids.TextAlign.Center },
new Syncfusion.EJ2.Grids.GridColumn(){ Field="aQuantity",Width="80",AllowEditing=false, HeaderText="AQuantity",TextAlign=Syncfusion.EJ2.Grids.TextAlign.Center },
new Syncfusion.EJ2.Grids.GridColumn(){ Field="qtyForOrder",Width="80",AllowEditing=true,EditType="numericedit",HeaderText="QtyForOrder",TextAlign=Syncfusion.EJ2.Grids.TextAlign.Center },
}
};
var FirstChild = new Syncfusion.EJ2.Grids.Grid()
{
DataSource = { },
QueryString = "orderNo",
Load = "OnLoadChild",
Columns = new List
new Syncfusion.EJ2.Grids.GridColumn(){ Field="sessionID",Visible=false, HeaderText="SessionID", Width="60",TextAlign=Syncfusion.EJ2.Grids.TextAlign.Center },
new Syncfusion.EJ2.Grids.GridColumn(){ Field="wyear",Visible=false, HeaderText="Wyear", Width="60",TextAlign=Syncfusion.EJ2.Grids.TextAlign.Center },
new Syncfusion.EJ2.Grids.GridColumn(){ Field="docType",Visible=false, HeaderText="DocType", Width="60", Format="C2", TextAlign=Syncfusion.EJ2.Grids.TextAlign.Center },
new Syncfusion.EJ2.Grids.GridColumn(){ Field="docNo",Visible=false, HeaderText="DocNo", Width="80",TextAlign=Syncfusion.EJ2.Grids.TextAlign.Center },
new Syncfusion.EJ2.Grids.GridColumn(){ Field="docLine", HeaderText="DocLine", Width="80",TextAlign=Syncfusion.EJ2.Grids.TextAlign.Center },
new Syncfusion.EJ2.Grids.GridColumn(){ Field="orderLine", HeaderText="OrderLine", Width="105",TextAlign=Syncfusion.EJ2.Grids.TextAlign.Center },
new Syncfusion.EJ2.Grids.GridColumn(){ Field="codeId", HeaderText="CodeId", Width="80",TextAlign=Syncfusion.EJ2.Grids.TextAlign.Center },
new Syncfusion.EJ2.Grids.GridColumn(){ Field="itemName", HeaderText="ItemName", Width="100",TextAlign=Syncfusion.EJ2.Grids.TextAlign.Center },
new Syncfusion.EJ2.Grids.GridColumn(){ Field="quantity", HeaderText="Quantity", Width="80",TextAlign=Syncfusion.EJ2.Grids.TextAlign.Center },
new Syncfusion.EJ2.Grids.GridColumn(){ Field="orderAmount", HeaderText="OrderAmount", Width="80",TextAlign=Syncfusion.EJ2.Grids.TextAlign.Center },
new Syncfusion.EJ2.Grids.GridColumn(){ Field="sellPriceWithVAT", HeaderText="SellPriceWithVAT", Width="80",TextAlign=Syncfusion.EJ2.Grids.TextAlign.Center },
},
ChildGrid = SecondChild
};
function btnclick(args) {
// get all the second level hierarchy grid
var secondlevelGrids = document.querySelectorAll("#Grid .e-grid .e-grid")
// #Grid – parent Grid id, 1st .e-grid – first level grid element class, 2nd .e-grid – second level grid element class
for (var i = 0; i < secondlevelGrids.length; i++) {
// save the batch edited records in Grid
secondlevelGrids[i].ej2_instances[0].editModule.batchSave();
}
}
|
function OnLoadChild2(args) {
var ajax = new ejs.base.Ajax({
type: "POST",
url: '/Home/getSaleOrderLines',
contentType: "application/json; charset=utf-8",
});
ajax.send().then(function (result) {
var data = JSON.parse(result);
// bind the dataSource using the dataManager with adaptor
this.dataSource = new ej.data.DataManager({
json: data, // bind the grid data
adaptor: new ej.data.RemoteSaveAdaptor(),
batchUrl: '/Home/BatchUpdate', // bind the method for batch editing
});
}.bind(this));
} |
@{
var SecondChild = new Syncfusion.EJ2.Grids.Grid()
{
DataSource = new Syncfusion.EJ2.DataManager()
{
Json = ViewBag.DataSource3.ToArray(),
BatchUrl = "/Home/BatchUpdate",
Adaptor = "RemoteSaveAdaptor"
},
-----
Toolbar = new List<string>() { "Add", "Edit", "Delete", "Update", "Delete" },
Load = "OnLoadChild2",
BeforeBatchSave = "beforeBatchSaveChild2",
Columns = new List<Syncfusion.EJ2.Grids.GridColumn> {
----
}
};
----
<script>
-----
function beforeBatchSaveChild2(args) {
var value1 = "";
var value2 = ""
if (args.batchChanges.changedRecords.length > 0) {
value1 = args.batchChanges.changedRecords[0].CustomerID
value2 = args.batchChanges.changedRecords[0].UnitID
} else if (args.batchChanges.addedRecords.length > 0) {
value1 = args.batchChanges.addedRecords[0].CustomerID
value2 = args.batchChanges.addedRecords[0].UnitID
} else {
value1 = args.batchChanges.deletedRecords[0].CustomerID;
value2 = args.batchChanges.deletedRecords[0].UnitID;
}
this.query.params = []
// send additional parameters to server side
this.query.addParams('CustomerID', value1);
this.query.addParams('UnitID', value2)
}
</script>
|
[HomeControllers.cs]
public IActionResult BatchUpdate([FromBody]CRUDModel batchmodel)
{
if (batchmodel.changed != null)
{
for (var i = 0; i < batchmodel.changed.Count(); i++)
{
var ord = batchmodel.changed[i];
OrdersDetails val = OrdersDetails.GetAllRecords().Where(or => or.OrderID == ord.OrderID).FirstOrDefault();
val.OrderID = ord.OrderID;
val.CustomerID = ord.CustomerID;
val.EmployeeID = ord.EmployeeID;
val.UnitID = ord.UnitID;
}
}
if (batchmodel.deleted != null)
{
for (var i = 0; i < batchmodel.deleted.Count(); i++)
{
OrdersDetails.GetAllRecords().Remove(OrdersDetails.GetAllRecords().Where(or => or.OrderID == batchmodel.deleted[i].OrderID).FirstOrDefault());
}
}
if (batchmodel.added != null)
{
for (var i = 0; i < batchmodel.added.Count(); i++)
{
OrdersDetails.GetAllRecords().Insert(0, batchmodel.added[i]);
}
}
var data = OrdersDetails.GetAllRecords().ToArray();
return Json(new { added = batchmodel.added, changed = batchmodel.changed, deleted = batchmodel.deleted,action = batchmodel.action, key = batchmodel.key }); ;
}
public class CRUDModel
{
public List<OrdersDetails> added { get; set; }
public List<OrdersDetails> changed { get; set; }
public List<OrdersDetails> deleted { get; set; }
public string key { get; set; }
public string action { get; set; }
public ParamObject Params { get; set; } // use paramObject to retrieve the additional parameters
}
public class ParamObject // define the required field as you want
{
public int? UnitID { get; set; }
public string CustomerID { get; set; }
}
|