<EjsGrid id="Grid" @ref="@grid" AllowPaging="true" AllowSorting="true" AllowFiltering="true" toolbar="@(new List<string>() {"Add", "Edit", "Delete", "Cancel", "Update" })">
<EjsDataManager Url="http://localhost:51972/api/Default" CrossDomain="true" Adaptor="Adaptors.WebApiAdaptor"></EjsDataManager>
<GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Normal"></GridEditSettings>
<GridColumns>
…………………………………………..
</GridColumns>
</EjsGrid> |
[HttpGet]
public object Get()
{
IQueryable<Order> data = db.GetAllOrders().AsQueryable();
var count = data.Count();
var queryString = Request.Query; //Based on this request query, handle the filter action
...
}
|
<EjsGrid TValue="Order" DataSource="@Orders" Height="315" AllowFiltering="true">
<GridFilterSettings Type="FilterType.Excel"></GridFilterSettings>
<GridEvents OnActionBegin="OnActionBegin" TValue="Order"></GridEvents>
...
</EjsGrid>
@code {
public void OnActionBegin(ActionEventArgs<Order> args)
{
if (args.RequestType.ToString() == "FilterChoiceRequest")
{
args.FilterChoiceCount = 2; //here, you can override the default take count of the filter records
}
}
...
}
|
[DefaultController.cs]
//Handle filter operations at server side
[HttpGet]
public object Get()
{
IQueryable<Order> data = db.GetAllOrders().AsQueryable();
var count = data.Count();
var queryString = Request.Query;
string filter = queryString["$filter"]; //filter query
string auto = queryString["$inlineCount"];
if (filter != null) //Filtering – Here you need to handle the filtering programmatically at server side, based on your Grid.
{
var newfiltersplits = filter;
var filtersplits = newfiltersplits.Split('(', ')', ' ');
var filterfield = filtersplits[1];
var filtervalue = filtersplits[3];
...
switch (filterfield)
{
case "OrderID": //Here we have performed filter by selecting the data matching the value
data = (from cust in data
where cust.OrderID.ToString() == filtervalue.ToString()
select cust);
break;
...
}
}
...
}
return take != 0 ? new { Items = data.Skip(skip).Take(take).ToList(), Count = data.Count() } : new { Items = data, Count = data.Count() };
}
|