var data = new ej.data.DataManager({
url: '/api/order',
adaptor: new ej.data.WebApiAdaptor
});
var grid = new ej.grids.Grid({
dataSource: data,
allowPaging: true,
toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel'],
editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal' },
columns: [
{ field: 'OrderID', headerText: 'ID', textAlign: 'Right', width: 120, isPrimaryKey: true },
{ field: 'CustomerID', headerText: 'Custome ID', textAlign: 'Right', width: 120 },
{ field: 'EmployeeID', headerText: 'Employee ID', textAlign: 'Right' }
]
});
grid.appendTo('#Grid'); |
public class OrderController : ApiController
{
// GET: api/Order
public object Get()
{
var queryString = System.Web.HttpContext.Current.Request.QueryString;
int skip = Convert.ToInt32(queryString["$skip"]); //paging
int take = Convert.ToInt32(queryString["$top"]);
var data = OrdersDetails.GetAllRecords();
return new
{
Items = data.Skip(skip).Take(take),
Count = data.Count()
// return order;
};
}
// POST: api/Order
[HttpPost]
public object Post([FromBody]OrdersDetails value)
{
OrdersDetails.GetAllRecords().Add(value);
var Data = OrdersDetails.GetAllRecords().ToList();
int count = Data.Count();
return Json(new { result = Data, count = count });
}
// PUT: api/Order/5
[HttpPut]
public object Put([FromBody]OrdersDetails value)
{
var ord = value;
OrdersDetails val = OrdersDetails.GetAllRecords().Where(or => or.OrderID == ord.OrderID).FirstOrDefault();
. . .
return value;
}
// DELETE: api/Order/5
public object Delete(int id)
{
OrdersDetails.GetAllRecords().Remove(OrdersDetails.GetAllRecords().Where(or => or.OrderID == id).FirstOrDefault());
return Json(id);
}
} |
var data = new ej.data.DataManager({
url: '/api/order',
adaptor: new ej.data.WebApiAdaptor
});
var grid = new ej.grids.Grid({
dataSource: data,
allowPaging: true,
actionComplete: (e) => {
if (e.requestType == 'save') {
grid.refresh();
}
},
toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel'],
editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal' },
columns: [
{ field: 'OrderID', headerText: 'ID', textAlign: 'Right', width: 120, isPrimaryKey: true },
{ field: 'CustomerID', headerText: 'Custome ID', textAlign: 'Right', width: 120 },
{ field: 'EmployeeID', headerText: 'Employee ID', textAlign: 'Right' }
]
});
grid.appendTo('#Grid'); |