Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
146351 | Jul 31,2019 01:13 PM UTC | Aug 5,2019 12:29 PM UTC | jQuery | 3 |
![]() |
Tags: ejmGrid |
In view
<div id="Grid">
</div>
<script >
var gridData = @Html.Raw(Json.Encode(@ViewBag.dataSource));
$(function () {
$("#Grid").ejGrid({
dataSource: ej.DataManager({
json: gridData,
insertUrl: "NormalInsert",
updateUrl: "NormalUpdate",
removeUrl: "NormalDelete",
adaptor: "remoteSaveAdaptor",
}),
allowPaging: true,
editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true },
toolbarSettings: { showToolbar: true, toolbarItems: [ej.Grid.ToolBarItems.Add, ej.Grid.ToolBarItems.Edit, ej.Grid.ToolBarItems.Delete, ej.Grid.ToolBarItems.Update, ej.Grid.ToolBarItems.Cancel] },
columns: [
{ field: "OrderID", headerText: "Order ID", isPrimaryKey: true, width: 75, textAlign: ej.TextAlign.Right },
{ field: "CustomerID", headerText: "Customer ID", width: 90 },
]
});
});
</script>
In controller
public class GridController : Controller
{
public static List<OrderDetails> order = new List<OrderDetails>();
public ActionResult GridFeatures()
{
if (order.Count() == 0)
BindDataSource();
ViewBag.datasource = order;
return View();
}
public ActionResult NormalUpdate(CRUDModel<OrderDetails> myObject) // method to update edited record
{
var ord = myObject.Value;
OrderDetails val = order.Where(or => or.OrderID == ord.OrderID).FirstOrDefault();
val.OrderID = ord.OrderID;
val.CustomerID = ord.CustomerID;
return Json(myObject.Value);
}
public ActionResult NormalInsert(OrderDetails value) //method to insert new record
{
order.Insert(order.Count, value);
return Json(order);
}
public ActionResult NormalDelete(CRUDModel<OrderDetails> value) //method to delete record
{
order.Remove(order.Where(or => or.OrderID == int.Parse(value.Key.ToString())).FirstOrDefault());
return Json(value);
}
} |
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.