SfAutoComplate Odata binding filtering wrong parameter.

Hi great supoort,

I have a SfAutoComplate like this;



dAcilanContext.AkademisyenId is int? type
Id is int type
Ad is string type

here is Query;


When i filtering my "SfAutoCompate" control like this;


 Request failed and oData query is generated like this;

/odata/Akademisyens?$count=true&$filter=contains(tolower(Id),'a')&$select=Ad,Id&$skip=0&$top=20

This query can't bring result because of "Id" has to be "Ad" 

How can i do that?
If i am going to do this: Value="Ad" Text="Id" it won't get existing value.

7 Replies 1 reply marked as answer

PM Ponmani Murugaiyan Syncfusion Team June 29, 2020 10:42 AM UTC

Hi Ben, 

Greetings from Syncfusion support. 
 
We would like to inform you that in Autocomplete component, mapping text field for AutoComplete will only update the text to list items in popup but functionalities like sorting and filtering will be performed based on the value field. So the type assigned to the component based on the value field. We request you to change the component type as string as like below code snippet.  
 
Please find the below link for more information regarding Autocomplete filtering. 
 
 
[Index.razor] 
 
<SfAutoComplete TValue="string" TItem="OrderDetails" Placeholder="Select a customer" Query="@Query"> 
    <SfDataManager Url="https://services.odata.org/V4/Northwind/Northwind.svc/Orders" Adaptor="Adaptors.ODataV4Adaptor" CrossDomain=true></SfDataManager> 
    <AutoCompleteFieldSettings Text="ShipName" Value="ShipName"></AutoCompleteFieldSettings> 
</SfAutoComplete> 
 
@code { 
    public Query Query = new Query().Select(new List<string> { "ShipName" }).Take(6).RequiresCount(); 
 
    public class OrderDetails 
    { 
        public int? OrderID { get; set; } 
        public string CustomerID { get; set; } 
        public int? EmployeeID { get; set; } 
        public double? Freight { get; set; } 
        public string ShipCity { get; set; } 
        public bool Verified { get; set; } 
        public DateTime? OrderDate { get; set; } 
        public string ShipName { get; set; } 
        public string ShipCountry { get; set; } 
        public DateTime? ShippedDate { get; set; } 
        public string ShipAddress { get; set; } 
    } 
} 
 
 
Kindly check with the above sample. Please get back us if you need further assistance. 

Regards, 
Ponmani M 


Marked as answer

BL Blazor July 1, 2020 09:07 AM UTC

In your example you are filtering with "ShipName".
But when user choose one item, how can i know which "OrderID" have choosen ?

Beacuse I want to register "OrderID


PM Ponmani Murugaiyan Syncfusion Team July 2, 2020 09:04 AM UTC

Hi Ben, 
 
Thanks for the update. 
 
You can get the OrderID of each item selected in the ValueChange event of AutoComplete component. Please find the code snippet and test sample for reference. 
 
[Index.razor] 
 
<SfAutoComplete TValue="string" TItem="OrderDetails" Placeholder="Select a customer" Query="@Query"> 
    <SfDataManager Url="https://services.odata.org/V4/Northwind/Northwind.svc/Orders" Adaptor="Adaptors.ODataV4Adaptor" CrossDomain=true></SfDataManager> 
    <AutoCompleteEvents TValue="string" ValueChange="ValueChangeHandler"></AutoCompleteEvents> 
    <AutoCompleteFieldSettings Text="ShipName" Value="ShipName"></AutoCompleteFieldSettings> 
</SfAutoComplete> 
 
@code { 
    public object AutoVal { get; set; } 
    public Query Query = new Query().Select(new List<string> { "ShipName", "OrderID" }).Take(6).RequiresCount(); 
 
    public class OrderDetails 
    { 
        public int? OrderID { get; set; } 
        public string CustomerID { get; set; } 
        public int? EmployeeID { get; set; } 
        public double? Freight { get; set; } 
        public string ShipCity { get; set; } 
        public bool Verified { get; set; } 
        public DateTime? OrderDate { get; set; } 
        public string ShipName { get; set; } 
        public string ShipCountry { get; set; } 
        public DateTime? ShippedDate { get; set; } 
        public string ShipAddress { get; set; } 
    } 
    public void ValueChangeHandler(Syncfusion.Blazor.DropDowns.ChangeEventArgs<string> args) 
    { 
        var item = JsonConvert.DeserializeObject<OrderDetails>(args.ItemData.ToString()); 
        var value = item.OrderID; 
    } 
} 
 
 
Kindly check with the above sample. Please get back us if you need further assistance. 
 
Regards,  
Ponmani M 



BL Blazor July 2, 2020 01:40 PM UTC

Thanks . Its great to know.
One last question.

Its interesting to not support Foreign key or primarary key as int for filtering .
Should i record "ShipName"  string as a foreign key on other tables? Becase i have to know which one(order detail) is selected later.

Hope i am clearly explained.


PM Ponmani Murugaiyan Syncfusion Team July 3, 2020 03:10 PM UTC

Hi Ben, 
 
Thanks for your update. 
 
Query: It’s interesting to not support Foreign key or primary key as int for filtering. 
 
No, AutoComplete will support int for filtering. As per your requirement you need to filter with string “ShipName”. But the AutoComplete component TValue type depends on the value field type mapped with fields property. Also we would like to inform you that we have converted the object args.ItemData to string in order to get the OrderID value and its type is Int. 
 
 
 
 
Please provide the additional details regarding the requirement for foreign key with the AutoComplete component to provide you the solution at earliest. 
 
Regards, 
Ponmani M 



BL Blazor July 5, 2020 09:37 AM UTC

Your example is working good.

I am about binding autocomplate to a integer.



Should i have to bind SfAutoComplate to a string type ?

I would like to bind my model to a integer ID (Key) and i would like to filter it with string value.

Fix me if i am wrong,
Let's say i am binding SfAuto Compalate to a string.
I full filled all controls(inputs) and i choose one item in sfautocompate.
I am going to save this entity. If my sfAutocomplete binded to a string that means i am going to save string to a database table. 
If i am going to get interger Id and save this there will be an other problem, which is;
When next time i am going to open this record again i sfautocomplate hasto understand that which item is selected.

But what i have choosen is just one row of an other table(which presented by sfAutocomplate.)
So i have to know this row ID number. 

If i describe to confusing, let's forget every thing.
Basically i think Value has to be int? and Text has tobe string . And i could be ableto filter acording to "text"




PM Ponmani Murugaiyan Syncfusion Team July 6, 2020 12:04 PM UTC

Hi Peter, 
 
Thanks for your update. 
 
We have validated your reported query. We suggest you to use the Blazor ComboBox component for your requirement to get the Value as int? and Text to be string. Please find the code snippet and test sample below for reference. 
 
[Index.razor] 
 
<p>ComboBox value is: @AutoVal</p> 
 
<SfComboBox  TValue="int?" TItem="OrderDetails" @bind-Value="@AutoVal" Placeholder="Select a customer" Query="@Query"> 
    <SfDataManager Url="https://services.odata.org/V4/Northwind/Northwind.svc/Orders" Adaptor="Adaptors.ODataV4Adaptor" CrossDomain=true></SfDataManager> 
    <ComboBoxFieldSettings Text="ShipName" Value="OrderID"></ComboBoxFieldSettings> 
</SfComboBox> 
 
@code { 
    public int? AutoVal; 
    public Query Query = new Query().Select(new List<string> { "ShipName", "OrderID" }).Take(6).RequiresCount(); 
 
    public class OrderDetails 
    { 
        public int? OrderID { get; set; } 
        public string CustomerID { get; set; } 
        public int? EmployeeID { get; set; } 
        public double? Freight { get; set; } 
        public string ShipCity { get; set; } 
        public bool Verified { get; set; } 
        public DateTime? OrderDate { get; set; } 
        public string ShipName { get; set; } 
        public string ShipCountry { get; set; } 
        public DateTime? ShippedDate { get; set; } 
        public string ShipAddress { get; set; } 
    } 
} 
 
OUTPUT: 
 
 
 
 
 
Regards,  
Ponmani M 


Loader.
Up arrow icon