<Grid>
@(Html.EJ().Grid<object>("Grid")
.Datasource(ds => ds.URL("/api/Orders").Adaptor(AdaptorType.WebApiAdaptor))
.AllowPaging()
.AllowGrouping()
.AllowSorting()
.AllowFiltering()
.FilterSettings(f => f.FilterType(FilterType.Excel))
.PageSettings(page => { page.PageSize(8); })
. . .
.Columns(col =>
{
. . .
})
)
<Web API controller>
NorthwindDataContext db = new NorthwindDataContext();
public PageResult<OrdersView> Get(ODataQueryOptions opts)
{
var emp = db.OrdersViews.Take(50).AsQueryable();
var count = emp.Count();
if (opts.OrderBy != null)
emp = opts.OrderBy.ApplyTo(emp); //perform sort
if (opts.Filter != null)
emp = opts.Filter.ApplyTo(emp, new ODataQuerySettings()).Cast<OrdersView>(); //perform filter
if (opts.InlineCount != null)
count = emp.ToList().Count;
if (opts.Skip != null)
emp = opts.Skip.ApplyTo(emp, new ODataQuerySettings()); //perform skip
if (opts.Top != null)
emp = opts.Top.ApplyTo(emp, new ODataQuerySettings()); //perform take
return new PageResult<OrdersView>(emp, null, count);
} |
<Grid>
@(Html.EJ().Grid<object>("Grid")
.Datasource(ds => ds.URL("/odata/Orders").Adaptor(AdaptorType.ODataV4Adaptor))
.AllowPaging()
.AllowGrouping()
.AllowSorting()
.AllowFiltering()
. . .
)
<Controller>
public async Task<Order> Put(int key, Order order) //Edit operation in database
{
var entity = await db.Orders.FindAsync(order.OrderID);
db.Entry(entity).CurrentValues.SetValues(order);
await db.SaveChangesAsync();
return order;
}
//// POST odata/Orders
public async Task<Order> Post(Order order) //Add Operation in database
{
db.Orders.Add(order);
await db.SaveChangesAsync();
return order;
}
//// DELETE odata/Orders(5)
public async Task<IHttpActionResult> Delete([FromODataUri] int key)
{
var od = await db.Orders.FindAsync(key);
if (od == null)
{
return NotFound();
}
db.Orders.Remove(od);
await db.SaveChangesAsync();
return StatusCode(HttpStatusCode.NoContent);
} |