var hostUrl = 'https://ej2services.syncfusion.com/production/web-services/';
var data = new ej.data.DataManager({
url: hostUrl + 'api/Orders',
adaptor: new ej.data.WebApiAdaptor(),
offline:true
});
var grid = new ej.grids.Grid({
dataSource: data,
allowPaging: true,
allowSorting:true,
allowGrouping:true,
allowFiltering:true,
editSettings:{allowAdding:true,allowEditing:true,allowDeleting:true},
toolbar:["Add","Edit","Delete","Update","Cancel"],
columns: [
{ field: 'OrderID', headerText: 'Order ID',isPrimaryKey:true, width: 130, textAlign: 'Right' },
{ field: 'CustomerID', headerText: 'Customer ID', width: 170 },
{ field: 'EmployeeID', headerText: 'Employee ID', width: 135, textAlign: 'Right' },
{ field: 'Freight', headerText: 'Freight', width: 160, textAlign: 'Right', format: 'C2' },
{ field: 'ShipCountry', headerText: 'Ship Country', width: 150, textAlign: 'Center' },
],
pageSettings: { pageCount: 3 }
});
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 query
int take = Convert.ToInt32(queryString["$top"]); //paging query
string filter = queryString["$filter"]; // filtering query
string sort = queryString["$orderby"]; // sorting query
var data = OrdersDetails.GetAllRecords();
if (sort != null) //Sorting
{
switch (sort)
{
// Perform sorting
}
}
if (filter != null)
{
// perform filtering
}
return new
{
Items = data.Skip(skip).Take(take),
Count = data.Count()
// return order;
};
}
// Perform adding
// POST: api/Order
[HttpPost]
public object Post([FromBody]OrdersDetails value)
{
OrdersDetails.GetAllRecords().Add(value);
. . .
return Json(new { result = Data, count = count });
}
// Perform Updating
// PUT: api/Order/5
[HttpPut]
public object Put([FromBody]OrdersDetails value)
{
. . .
return value;
}
// Perform Deleting
// DELETE: api/Order/5
public object Delete(int id)
{
OrdersDetails.GetAllRecords().Remove(OrdersDetails.GetAllRecords().Where(or => or.OrderID == id).FirstOrDefault());
return Json(id);
}
} |