I have a grid that uses the remote save adaptor. I have set it up so that I can add and edit individual records with the edit dialog. I also need to be able to batch save the records in the grid with a button click.
Code:
@Html.EJS().Grid("ContainerGrid").DataSource(DataManager => { DataManager.Json(@Model.ContainerTransactions.ToArray()).InsertUrl("Home/AddContainerItem").UpdateUrl("Home/UpdateContainerItem").RemoveUrl("Home/DeleteContainerItem").Adaptor("RemoteSaveAdaptor"); }).Width("auto").Columns(col =>
{
col.Field("InventoryID").HeaderText("Item").IsPrimaryKey(true).Width("40").EditType("dropdownedit").Edit(new { @params = itemDropDown }).ValidationRules(new { required = true }).Add();
col.Field("ContainerID").ValueAccessor(containerAccessor).IsPrimaryKey(true).Visible(false).Add();
col.Field("Description").HeaderText("Description").ValueAccessor(descriptionAccessor).Width("90").Add();
...
}).ActionBegin("actionBegin").ActionComplete("actionComplete").EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Dialog); }).Toolbar(new List<string>() { "Add", "Edit","Delete" }).Render()
<div class="row mt-2 mb-2">
<div class="col-sm-12 col-lg-12 col-md-12">
<div id="submitbutton" class="float-right">
<input type="submit" value="Confirm" class="btn btn-primary"/>
</div>
<div id="submitbutton" class="float-right mr-2">
<input type="submit" value="Cancel" class="btn btn-primary"/>
</div>
</div>
</div>
When I click the confirm button below I need to be able to batch save the records in the grid.
Index.cshtml
<button class="c-btn">Submit </button>
@Html.EJS().Grid("FlatGrid").DataSource(dataManager => { dataManager.Json(ViewBag.DataSource2.ToArray()).BatchUrl("/Home/BatchUpdate").Adaptor("RemoteSaveAdaptor");
}).Width("800").Columns(col =>
{
col.Field("UnitID").HeaderText("Unit ID").Width("120").IsPrimaryKey(true).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("N1").HeaderText("N1").Width("125").Format("N0").Add();
col.Field("N2").HeaderText("N2").Width("170").Format("N0").Add();
}).AllowPaging().EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Batch); }).Toolbar(new List<string>
() { "Add", "Edit", "Delete", "Cancel" }).Render()
<script>
document.getElementsByClassName("c-btn")[0].addEventListener("click", () => {
var grid = document.getElementsByClassName("e-grid")[0].ej2_instances[0];
grid.endEdit();
})
</script>
|
I need to add/edit/delete one record at a time so that each record is set to pending. Then I need to be able to click the confirm button and update all of the records to be submitted. I am using a Model from a view to populate my grid. How can I pass the grid data to the controller when I click the confirm button? Maybe through a button click that sends the grid data to ajax call?
I have tried to do it this way and I am getting the data from the grid but when am getting null in the action method on the controller.
document.getElementById("submitbtn").addEventListener("click", function () {
debugger;
var gridObj = document.getElementById("ContainerGrid").ej2_instances[0];
var g = gridObj.dataSource;
var ajax = new ej.base.Ajax({
url: 'Home/SubmitContainerTransactions',
type: 'POST',
data: JSON.stringify( g )
});
ajax.send();
});
Controller
public ActionResult SubmitContainerTransactions([FromBody] List<ContainerTransaction> containerTransactions)
{
return Json(new { result = containerTransactions });
}
Index.cshtml
<button class="c-btn">Submit </button>
@Html.EJS().Grid("FlatGrid").DataSource(dataManager => { dataManager.Json(ViewBag.DataSource2.ToArray()).BatchUrl("/Home/BatchUpdate").Adaptor("RemoteSaveAdaptor");
}).Width("800").Columns(col =>
{
col.Field("UnitID").HeaderText("Unit ID").Width("120").IsPrimaryKey(true).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("N1").HeaderText("N1").Width("125").Format("N0").Add();
col.Field("N2").HeaderText("N2").Width("170").Format("N0").Add();
}).AllowPaging().EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Batch); }).Toolbar(new List<string>
() { "Add", "Edit", "Delete", "Cancel" }).Render()
<script>
document.getElementsByClassName("c-btn")[0].addEventListener("click", () => {
var grid = document.getElementsByClassName("e-grid")[0].ej2_instances[0];
grid.endEdit(); // update the changes to the server side.
})
</script>
|