Custom adaptor for auto complete
I see that the latest version support custom adaptors but I can't find any documentation and haven't figured out how to make one. I have a business object that returns the data I need and no web api. I'd like to write a custom adaptor to interact with my business object and return results. But how?
SIGN IN To post a reply.
1 Reply
GG
Gopi Govindasamy
Syncfusion Team
August 23, 2019 10:06 AM UTC
Hi Paul,
We have checked your requirement for “custom adaptors with autocomplete component”. We have prepared sample for custom adaptor to load the datasource into autocomplete component. Please find the sample and code snippet for your reference.
|
<EjsAutoComplete TValue="string">
<EjsDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></EjsDataManager>
<AutoCompleteFieldSettings Value="CustomerID"></AutoCompleteFieldSettings>
</EjsAutoComplete>
@code{
public class Orders
{
public Orders() { }
public Orders(int OrderID, string CustomerID)
{
this.OrderID = OrderID;
this.CustomerID = CustomerID;
}
public int OrderID { get; set; }
public string CustomerID { get; set; }
}
public class CustomAdaptor : DataAdaptor
{
static readonly HttpClient client = new HttpClient();
public static List<OrdersDetails> order = OrdersDetails.GetAllRecords();
public override object Read(DataManagerRequest dm, string key = null)
{
IEnumerable<OrdersDetails> DataSource = order;
if (dm.Search != null && dm.Search.Count > 0)
{
DataSource = DataOperations.PerformSearching(DataSource, dm.Search); //Search
}
if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting
{
DataSource = DataOperations.PerformSorting(DataSource, dm.Sorted);
}
if (dm.Where != null && dm.Where.Count > 0) //Filtering
{
DataSource = DataOperations.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
}
int count = DataSource.Cast<OrdersDetails>().Count();
if (dm.Skip != 0)
{
DataSource = DataOperations.PerformSkip(DataSource, dm.Skip); //Paging
}
if (dm.Take != 0)
{
DataSource = DataOperations.PerformTake(DataSource, dm.Take);
}
return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource;
}
}
} |
We will include this custom adaptor document in our UG, which will be available at the end of August 2019.
Regards,
Gopi G.
Gopi G.
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
PS Paul Skelton
- Aug 22, 2019 10:03 PM UTC
- Aug 23, 2019 10:06 AM UTC