|
<SfGrid TValue="Orders" AllowPaging="true">
<SfDataManager Url="api/Default" Adaptor="Adaptors.WebApiAdaptor"></SfDataManager>
...
</SfGrid>
[HttpGet]
public async Task<object> Get()
{
...
var data = order.AsQueryable();
var queryString = Request.Query;
string auto = queryString["$inlineCount"];
if (queryString.Keys.Contains("$inlinecount"))
{
StringValues Skip;
StringValues Take;
int skip = (queryString.TryGetValue("$skip", out Skip)) ? Convert.ToInt32(Skip[0]) : 0;
int top = (queryString.TryGetValue("$top", out Take)) ? Convert.ToInt32(Take[0]) : data.Count();
var count = data.Count();
return new { Items = data.Skip(skip).Take(top), Count = count };
}
...
}
|
|
// Implementing custom adaptor by extending the DataAdaptor class
public class CustomAdaptor : DataAdaptor
{
// Performs data Read operation
public override object Read(DataManagerRequest dm, string key = null)
{
IEnumerable<Order> DataSource = Orders;
// send request to server and perform your actions and return data
int count = DataSource.Cast<Order>().Count();
if (dm.Skip != 0)
{
//Paging
DataSource = DataOperations.PerformSkip(DataSource, dm.Skip);
}
if (dm.Take != 0)
{
DataSource = DataOperations.PerformTake(DataSource, dm.Take);
}
return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource;
}
}
|
Hi Lukasz,
Thanks for the update.
Based on your requirement, we suggest you to achieve your requirement by using CustomAdaptor. CustomAdaptor’s Read method will trigger for each action like filtering, searching, sorting, paging etc. and certain actions can be performed in it. Once the data operation is executed, data has to be returned in the form Result and Count to display in the Grid.
Refer the below code example.
// Implementing custom adaptor by extending the DataAdaptor classpublic class CustomAdaptor : DataAdaptor{// Performs data Read operationpublic override object Read(DataManagerRequest dm, string key = null){IEnumerable<Order> DataSource = Orders;// send request to server and perform your actions and return dataint count = DataSource.Cast<Order>().Count();if (dm.Skip != 0){//PagingDataSource = DataOperations.PerformSkip(DataSource, dm.Skip);}if (dm.Take != 0){DataSource = DataOperations.PerformTake(DataSource, dm.Take);}return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource;}}
Please find the below documentation for your reference.
Reference:
Please let us know if you have any concerns.
Regards,Jeevakanth SP.
|
<SfGrid TValue="Order" AllowFiltering="true" Toolbar="@(new List<string> { "Add", "Edit", "Delete", "Update", "Cancel", "Search" })" AllowSorting="true" AllowPaging="true">
<SfDataManager Adaptor="Adaptors.CustomAdaptor">
<CustomAdaptor></CustomAdaptor>
</SfDataManager>
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true"></GridEditSettings>
<GridColumns>
<GridColumn Field="OrderID" HeaderText="Order ID" IsPrimaryKey="true" IsIdentity="true" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field="CustomerID" HeaderText="Customer Name" Width="150"></GridColumn>
<GridColumn Field="EmployeeID" HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" EditType="EditType.NumericEdit" Width="120"></GridColumn>
</GridColumns>
</SfGrid>
[CustomAdaptor.razor] |