.Datasource((System.Data.DataTable)Model.AllImports)
I'd like to be able to edit values in one column on the second grid inline in a batch mode and then click an external submit button to save the values and re-load the form, because based on the entered values the content of the first grid can change.
I tried different methods using your knowledge base, documentation and forum search, but I can't make it work.
Here is my view (since I don't have issues with the first and the third grid I left only the second grid definition ("DeferredMapFlatGrid") intact and as you can see from commented out lines I tried a few things there):
@model CART.Models.Imports
<div id="ImportsToReconcile">
<h3> Imports to be reconciled </h3>
@(Html.EJ().Grid<object>("HierarchyImportsGrid")
.Datasource((System.Data.DataTable)Model.UnrecedImports)
...
)
<br />
<div>
@using (Html.BeginForm())
{
@Html.EJ().Button("btnReconcileSelected").Text("Reconcile Selected").Size(ButtonSize.Large).Type(ButtonType.Submit).ShowRoundedCorner(true).ContentType(ContentType.TextAndImage).PrefixIcon("e-righttick").Width("170px").ClientSideEvents(e => e.Click("btnReconcileSelected_Clicked"))
@Html.HiddenFor(m => m.ListOfIDs)
}
</div>
</div>
<div id="MissingSedols">
<h3> Missing SEDOLs Mapping </h3>
@(Html.EJ().Grid<object>("DeferredMapFlatGrid")
//.Datasource(datasource => datasource.Json((System.Data.DataTable)Model.DeferredMapMissingOnly).BatchURL("Home/MDBatchUpdate").Adaptor(AdaptorType.UrlAdaptor))
//.Datasource((System.Data.DataTable)Model.DeferredMapMissingOnly)
//.Datasource(ds => ds.BatchURL("MDBatchUpdate").Adaptor(AdaptorType.UrlAdaptor))
//.Datasource(ds => ds.Json((System.Data.DataTable)Model.DeferredMapMissingOnly).UpdateURL("NormalUpdate").Adaptor(AdaptorType.RemoteSaveAdaptor))
.Datasource((System.Data.DataTable)Model.DeferredMapMissingOnly)
.EditSettings(edit => { edit.AllowEditing().EditMode(EditMode.Batch); })
.AllowSorting()
.AllowSelection(true)
.Columns(col =>
{
col.HeaderText("#").TextAlign(TextAlign.Center).Template("{{:~index + 1}}").Width(15).Add();
col.Field("id").HeaderText("ID").IsPrimaryKey(true).Width(0).Add();
col.Field("output_sedol").HeaderText("Mismatched Sedol").AllowEditing(false).Width(60).Add();
col.Field("notes").HeaderText("Mismatched Security Name").AllowEditing(false).Width(120).Add();
col.Field("headstock_sedol").HeaderText("Map To Sedol").EditType(EditingType.String).Width(60).Add();
col.Field("insert_date").HeaderText("Inserted On").AllowEditing(false).Width(45).Format("{0:dd-MMM-yy}").Add();
col.Field("comments").HeaderText("Comments").AllowEditing(true).Width(200).Add();
})
)
</div>
@using (Html.BeginForm("IndexSaveMap", "Home"))
{
@Html.EJ().Button("btnUpdateMappings").Text("Update Mappings").Size(ButtonSize.Large).Type(ButtonType.Submit).ShowRoundedCorner(true).ContentType(ContentType.TextAndImage).PrefixIcon("e-save").Width("170px").ClientSideEvents(e => e.Click("btnUpdateMappings_Clicked"))
}
<br />
<div id="ImportHistory">
<h3>History Of Imports</h3>
@(Html.EJ().Grid<object>("ImportHistoryFlatGrid")
.Datasource((System.Data.DataTable)Model.AllImports)
...
)
</div>
@section scripts
{
<script type="text/javascript">
function btnUpdateMappings_Clicked() {
$("#ListOfIDs").val("Mappings Updated");
var obj = $("#DeferredMapFlatGrid").ejGrid("instance")
obj.batchSave()
}
</script>
}
Here is the controller:
using System.Collections.Generic;
using System.Web.Mvc;
using CART.Models;
namespace CART.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
Imports imports = new Imports();
return View(imports);
}
[HttpPost]
public ActionResult Index(Imports imports)
{
string selected = imports.ListOfIDs;
if (selected != null)
{
if (selected == "Mappings Updated")
{
string newvalue = imports.DeferredMapMissingOnly.Rows[0]["headstock_sedol"].ToString();
}
else
{
imports.ReconcileImportsByIDs(selected);
}
}
Imports _imports = new Imports();
return View(_imports);
}
[HttpPost]
public ActionResult IndexSaveMap(Imports imports)
{
string newvalue = imports.DeferredMapMissingOnly.Rows[0]["headstock_sedol"].ToString();
Imports _imports = new Imports();
return View(_imports);
}
public ActionResult MDBatchUpdate(List<object> changed, List<object> added, List<object> deleted)
{
Imports imports = new Imports();
string s;
if (changed != null)
s = "c";
//OrderRepository.Update(changed);
if (deleted != null)
s = "d";
//OrderRepository.Delete(deleted);
if (added != null)
s = "a";
//OrderRepository.Add(added);
var data = imports.DeferredMapMissingOnly;
return Json(data, JsonRequestBehavior.AllowGet);
}
}
}
Can you please help?
1.Do you want to reload the data of First Grid based on the changed value of the Second Grid?
@(Html.EJ().Grid<object>("FlatGrid")
.Datasource((IEnumerable<object>)ViewBag.datasource)
.AllowScrolling()
.
.
.
@Html.EJ().Button("btnReconcileSelected").Text("Reconcile Selected").Type(ButtonType.Submit).ShowRoundedCorner(true).ClientSideEvents(e => e.Click("btnReconcileSelected_Clicked"))
@(Html.EJ().Grid<object>("FlatGrid1")
.Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.datasource1).BatchURL("BatchUpdate").Adaptor(AdaptorType.RemoteSaveAdaptor)) // second grid with remotesaveadaptor to save the value changed in database .
.
.
.ClientSideEvents(eve=>eve.ActionComplete("complete")))
@Html.EJ().Button("btnUpdateMappings").Text("Update Mappings").Type(ButtonType.Submit).ShowRoundedCorner(true).ClientSideEvents(e => e.Click("btnUpdateMappings_Clicked"))
.
.
.
.
function btnUpdateMappings_Clicked(args) {
var grid = $("#FlatGrid1").ejGrid("instance");
grid.batchSave();
}
function complete(args) {
if(args.requestType == "batchsave") {
var grid = $("#FlatGrid").ejGrid("instance"); // firstGrid
grid.dataSource(this.model.dataSource.dataSource.json);
}
} |