public ActionResult Insert(EditableOrder value)
{
Random ran = new Random();
value.OrderID = ran.Next();
OrderRepository.Add(value);
var data = OrderRepository.GetAllRecords();
return Json(value, JsonRequestBehavior.AllowGet);
} |
@(Html.EJ().Grid<object>("Grid")
.. .
.AllowResizeToFit()
. . .
. . .
)
|
@(Html.EJ().Grid<object>("BatchEditing")
.Datasource(ds =>
ds.Json((IEnumerable<object>)ViewBag.data)
.BatchURL("/Home/BatchUpdate")
.Adaptor(AdaptorType.RemoteSaveAdaptor))
.EditSettings(edit =>
{
edit.AllowAdding();
edit.AllowEditing();
edit.AllowDeleting();
edit.EditMode(EditMode.Batch);
})
..
)
|
public ActionResult DataSource(Syncfusion.JavaScript.DataManager dm)
{
IEnumerable datasource = GridData;
DataOperations operation = new DataOperations();
//Each actions in Grid must be handled here
if (dm.Where != null)//for filtering
datasource = operation.PerformWhereFilter(datasource, dm.Where, dm.Where[0].Condition);
int count = datasource.AsQueryable().Count();
if (dm.Sorted != null)//for sorting
datasource = operation.PerformSorting(datasource, dm.Sorted);
if (dm.Skip != null)//for paging
datasource = operation.PerformSkip(datasource, dm.Skip);
if (dm.Take != null)//for paging
datasource = operation.PerformTake(datasource, dm.Take);
return Json(new { result = datasource, count = count }, JsonRequestBehavior.AllowGet);
}
@(Html.EJ().Grid<object>("Grid")
.Datasource(ds =>
ds.URL("/Home/DataSource")
.Adaptor(AdaptorType.UrlAdaptor))
. ..
)
|
public ActionResult Delete(int key)
{
var value = OrderRepository.GetAllRecords().Where(e => e.OrderID == key).FirstOrDefault();
OrderRepository.Delete(key);
return Json(value, JsonRequestBehavior.AllowGet);
}
//or
public void Delete(int key)
{
OrderRepository.Delete(key);
} |