Why does autocomplete filter on values instead of text? You would think that the default case would be for the user to enter the text that is needed to search among the names that get displayed. Instead, the default filter seems to be on the value.
|
<SfAutoComplete @ref="autocompleteObj" Autofill="false" Enabled="true" CssClass="e-outline" TValue="string" Placeholder="e.g. Australia" TItem="ProjectModel" DataSource="@Project">
<AutoCompleteFieldSettings Value="ProjectCustomerName"></AutoCompleteFieldSettings>
<AutoCompleteEvents TValue="string" Filtering="onFlitering"></AutoCompleteEvents>
</SfAutoComplete>
@code {
SfAutoComplete<string, ProjectModel> autocompleteObj;
public class ProjectModel
{
public string ProjectCustomerName { get; set; }
public string ProjectID { get; set; }
}
public Query query;
List<ProjectModel> Project = new List<ProjectModel>
{
new ProjectModel() { ProjectCustomerName = "Australia", ProjectID = "AU" },
new ProjectModel() { ProjectCustomerName = "Bermuda", ProjectID = "BM" },
new ProjectModel() { ProjectCustomerName = "Canada", ProjectID = "CA" },
new ProjectModel() { ProjectCustomerName = "Cameroon", ProjectID = "DK" },
};
public void onFlitering(FilteringEventArgs e)
{
e.PreventDefaultAction = true;
query = new Query().Where(new WhereFilter()
{
Field = "ProjectID",
value = e.Text,
Operator = "startswith",
IgnoreCase = true
});
this.autocompleteObj.Filter(Project, query);
}
} |
Hmm why isn't filtering on text the default? The user may not have a clue what the value is.
Hi Steven Cramer,
We believe you might be interested in filtering the data of the autocomplete component using a text field. By default, value binding and filtering operations are solely based on the Value field within the AutoComplete component. However, mapping the text field for AutoComplete will update the text displayed in the popup list items. Please note that sorting and filtering will still be performed based on the value field.
Otherwise, we recommend using the Combobox component with allowfiltering as true, as it allows you to map both the text and value fields for the component. With the combobox, you can map both the key and value to the component.
For further guidance and to explore a documentation, please refer to the provided link.
ComboBox - https://blazor.syncfusion.com/documentation/combobox/getting-started
Regards,
Priyanka K