BoldSignEasily embed eSignatures in your .NET applications. Free sandbox with native SDK available.
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);
}
} |