Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
141094 | Nov 23,2018 10:41 AM UTC | Jan 28,2019 07:31 AM UTC | ASP.NET MVC - EJ 2 | 7 |
![]() |
Tags: Grid |
[index.cshtml]
@Html.EJS().Grid("Grid").ActionBegin("actionBegin").DataSource(dataManager =>{dataManager.Json(ViewBag.dataSource).InsertUrl("/Home/Insert").RemoveUrl("/Home/Delete").UpdateUrl("/Home/Update").Adaptor("RemoteSaveAdaptor");
}).EditSettings(edit =>
{
edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).ShowDeleteConfirmDialog(true)
.AllowEditOnDblClick(false).Mode(Syncfusion.EJ2.Grids.EditMode.Dialog);
}).Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").Visible(false).IsIdentity(true).IsPrimaryKey(true).Width("30%").Add();
col.Field("EmployeeID").HeaderText("Employee ID").Width("150").Add();
col.Field("CustomerID").HeaderText("CustomerID").Width("70").Add();
}).AllowPaging().Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render()
</div>
<script>
var PkValue = 1000;
function actionBegin(args) {
if (args.requestType == 'save' && args.action == 'add') {
args.data[this.getPrimaryKeyFieldNames()[0]] = ++PkValue;
}
}
</script>
[controller]
public ActionResult Index()
{
ViewBag.dataSource = OrdersDetails.GetAllRecords().ToArray();
return View();
}
public ActionResult Update(OrdersDetails value)
{
var ord = value;
OrdersDetails val = OrdersDetails.GetAllRecords().Where(or => or.OrderID == ord.OrderID).FirstOrDefault();
val.OrderID = ord.OrderID;
val.EmployeeID = ord.EmployeeID;
val.CustomerID = ord.CustomerID;
return Json(value);
}
//insert the record
public ActionResult Insert(OrdersDetails value)
{
OrdersDetails.GetAllRecords().Insert(0, value);
return Json(new { data = value });
}
//Delete the record
public ActionResult Delete(int key)
{
OrdersDetails.GetAllRecords().Remove(OrdersDetails.GetAllRecords().Where(or => or.OrderID == key).FirstOrDefault());
var data = OrdersDetails.GetAllRecords();
return Json(data);
}
. . .
}
|
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.