|
<div>
<B>Master Grid</B>
@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.dataSource).Width("auto").SelectedRowIndex(0).Columns(col =>
{
col.Field("EmployeeID").HeaderText("EmployeeID").IsPrimaryKey(true).Add();
...
}).RowSelected("selected").Render()
</div>
<div>
<B>Child Grid</B>
@Html.EJS().Grid("Grid1").DataSource((IEnumerable<object>)ViewBag.dataSource1).Columns(col =>
{
col.Field("EmployeeID").HeaderText("EmployeeID").IsPrimaryKey(true).Add();
...
}).Render()
</div>
<script>
function selected(args) {
var data = @Html.Raw(Json.Encode(ViewBag.datasource));
var employeeID = args.data.EmployeeID;
var detaildata = new ej.data.DataManager(data).executeLocal(new ej.data.Query().where("EmployeeID", "equal", employeeID, false).take(10));
var grid = document.getElementById("Grid1").ej2_instances[0];
grid.dataSource = new ej.data.DataManager(detaildata.slice(0, 5)).dataSource.json;
}
</script> |
|
function btnClick(args) {
var grid = $("#DataGrid").ejGrid("instance"); //This is the EJ1 grid instance
grid.batchSave();
} |
|
@Html.EJS().Grid("DataGrid").DataSource(dataManager => { dataManager.Url(@Url.Action("UrlDatasource", "AirQuote")).BatchUrl("BatchUpdate").Adaptor("UrlAdaptor"); }).Columns(col =>
{
. . . . . . . .
. . . . . . . .
}).EditSettings(e => { e.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Normal); }).AllowPaging().PageSettings(page => page.PageCount(2)).Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render() |
@Html.EJS().TextBox("CODE").Placeholder("Code").FloatLabelType(FloatLabelType.Auto).Render()
@Html.EJS().TextBox("REFERENCE").Placeholder("Reference").FloatLabelType(FloatLabelType.Auto).Render()
@Html.EJS().DatePicker("DATE").Placeholder("Date").FloatLabelType(FloatLabelType.Auto).Render()
@Html.EJS().DatePicker("TARGETDATE").Placeholder("Target Date").FloatLabelType(FloatLabelType.Auto).Render()
|
@Html.EJS().Grid("DataGrid").DataSource(dataManager => { dataManager.Url(@Url.Action("UrlDatasource", "AirQuote")).BatchUrl("BatchUpdate").Adaptor("UrlAdaptor"); }).Columns(col => { . . . . . . . }).EditSettings(e => { e.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Normal); }).AllowPaging().PageSettings(page => page.PageCount(2)).Toolbar(new List() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render() |
|
@Html.EJS().Grid("DataGrid").DataSource(dataManager => { dataManager.Url(@Url.Action("UrlDatasource", "AirQuote")).BatchUrl("BatchUpdate").Adaptor("UrlAdaptor"); }).Columns(col =>
{ . . . . . . . }).EditSettings(e => { e.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Normal); }).AllowPaging().PageSettings(page => page.PageCount(2)).Toolbar(new List() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render() public class AirQuoteController : Controller
{
public ActionResult AirQuote()
{
return View();
}
public ActionResult BatchDataSource(DataManagerRequest dm)
{
IEnumerable DataSource = AirDetailRepository.GetAllRecords().ToList();
BatchDataResult result = new BatchDataResult();
DataOperations obj = new DataOperations();
int count = DataSource.Cast().Count();
if (dm.Skip != 0)
{
DataSource = obj.PerformSkip(DataSource, dm.Skip);
}
if (dm.Take != 0)
{
DataSource = obj.PerformTake(DataSource, dm.Take);
}
result.result = DataSource;
return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource);
}
public ActionResult BatchUpdate(List changed, List added, List deleted, List Form)
{
DevContext db = new DevContext();
if (changed != null)
AirDetailRepository.Update(changed);
if (deleted != null)
AirDetailRepository.Delete(deleted);
if (added != null)
AirDetailRepository.Add(added);
if (Form != null)
AirHeaderRepository.Add(Form);
var data = AirDetailRepository.GetAllRecords();
return Json(data, JsonRequestBehavior.AllowGet);
}
public class BatchDataResult
{
public IEnumerable result { get; set; }
public int count { get; set; }
}
} |
Hi Daniel,
Before we start providing solution on your query, we need more information to collect. Please share the below details that will be helpful for us to provide better solution.
- From your screenshot we suspect after entering the value you want to save the values to the grid. So please confirm it was your requirement.
- Please confirm you have place the grid inside the form?
Regards,Rajapandi R
|
<div class="control-section">
@using (Html.BeginForm())
{
@Html.EJS().Grid("DefaultPaging").DataSource(ds => ds.Url("/Home/UrlDatasource").Adaptor("UrlAdaptor").InsertUrl("/Home/Insert").RemoveUrl("/Home/Remove").UpdateUrl("/Home/Update")).Columns(col =>
{
. . . . . . . .
}).Height("400").AllowPaging().Toolbar(new List<string>
() { "Add", "Edit", "Delete", "Cancel" }).AllowFiltering().FilterSettings(filter => filter.Type(Syncfusion.EJ2.Grids.FilterType.Menu)). ActionBegin("begin").EditSettings(edit => { edit.AllowEditing(true).AllowAdding(true).AllowDeleting(true); }).Render()
}
</div>
<div>
<button type="submit" onclick="btnClick()" value="Save" class="btn btn-primary">Save</button>
</div>
<script>
var flag = false;
function begin(args) {
if (args.requestType === "save" && args.action === "add" && flag == false) {
args.cancel = true;
flag = true;
}
else {
flag = false;
args.cancel = false;
}
}
function btnClick(args) { //button click
var grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0];
grid.endEdit(); //It sends the post to the controller and saved in the database
}
</script>
|
|
Index.cshtml
@using (Html.BeginForm("FormPost", "Home", FormMethod.Post)) //this url helps to hit the server method with the form value
{
@Html.EJS().DatePicker("date").Placeholder("Date").Render()
@Html.EJS().TextBox("code").Placeholder("Code").Render()
@Html.EJS().Button("btn").Content("Save").Render()
}
|
|
HomeController.cs
public class HomeController : Controller
{
public static List<FormControls> formdata = new List<FormControls>();
public class FormControls
{
public int code { get; set; }
public DateTime date { get; set; }
}
[HttpPost]
public ActionResult FormPost(FormControls form)
{
var ins = form;
formdata.Insert(0, ins); //it helps to update your record in your database
}
}
|
Hi Daniel,
From validating your query, we found you are try to submit the two forms in single button click. But by default we cannot able to submit the two forms in single button click. We have to submit only one form at the time of form submit. In your code example, you are place the grid inside the form. Inside the form you have to keep only the Input controls. But Grid is not a form component. Please refer the below documentation for information.
Documentation: https://ej2.syncfusion.com/aspnetmvc/documentation/common/strongly-typed-html-helper/
If you want Grid inside the form, Please refer the below code example for more information.
In this below code example, we have rendered the grid inside the form and prevent the default Grid action while saving the added record by using flag variable. Now you can able to save the added record only by button click.
<div class="control-section">@using (Html.BeginForm()){@Html.EJS().Grid("DefaultPaging").DataSource(ds => ds.Url("/Home/UrlDatasource").Adaptor("UrlAdaptor").InsertUrl("/Home/Insert").RemoveUrl("/Home/Remove").UpdateUrl("/Home/Update")).Columns(col =>{. . . . . . . .}).Height("400").AllowPaging().Toolbar(new List<string>() { "Add", "Edit", "Delete", "Cancel" }).AllowFiltering().FilterSettings(filter => filter.Type(Syncfusion.EJ2.Grids.FilterType.Menu)). ActionBegin("begin").EditSettings(edit => { edit.AllowEditing(true).AllowAdding(true).AllowDeleting(true); }).Render()}div><div><button type="submit" onclick="btnClick()" value="Save" class="btn btn-primary">Savebutton>div><script>var flag = false;function begin(args) {if (args.requestType === "save" && args.action === "add" && flag == false) {args.cancel = true;flag = true;}else {flag = false;args.cancel = false;}}function btnClick(args) { //button clickvar grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0];grid.endEdit(); //It sends the post to the controller and saved in the database}script>
If you want save the input control form values to the databased, for your reference we have prepared a sample. So we suggest you to follow the below way to achieve your requirement. Please refer the code example for more information.
Index.cshtml@using (Html.BeginForm("FormPost", "Home", FormMethod.Post)) //this url helps to hit the server method with the form value{@Html.EJS().DatePicker("date").Placeholder("Date").Render()@Html.EJS().TextBox("code").Placeholder("Code").Render()@Html.EJS().Button("btn").Content("Save").Render()}
HomeController.cspublic class HomeController : Controller{public static Listformdata = new List(); public class FormControls{public int code { get; set; }public DateTime date { get; set; }}[HttpPost]public ActionResult FormPost(FormControls form){var ins = form;formdata.Insert(0, ins); //it helps to update your record in your database}}
For your both queries we have prepared a sample and video demo. Please refer the below sample and video demo for more information.
Regards,Rajapandi R