|
@using Syncfusion.Blazor.DropDowns
@using Syncfusion.Blazor.Data
<SfAutoComplete @ref="autoObj" ID="autocomplete" TValue="string" TItem="Games" Placeholder="e.g. Australia" DataSource="@LocalData">
<AutoCompleteFieldSettings Value="Text"></AutoCompleteFieldSettings>
<AutoCompleteEvents Filtering="OnFiltering" TValue="string"></AutoCompleteEvents>
</SfAutoComplete>
@code {
SfAutoComplete<string, Games> autoObj;
public Query query;
public class Games
{
public string ID { get; set; }
public string Text { get; set; }
}
List<Games> LocalData = new List<Games> {
new Games() { ID= "Game1", Text= "American Football" },
new Games() { ID= "Game2", Text= "Badminton" },
new Games() { ID= "Game3", Text= "Basketball" },
new Games() { ID= "Game4", Text= "Cricket" },
new Games() { ID= "Game5", Text= "Football" },
new Games() { ID= "Game6", Text= "Golf" },
new Games() { ID= "Game7", Text= "Hockey" },
new Games() { ID= "Game8", Text= "Rugby"},
new Games() { ID= "Game9", Text= "Snooker" },
new Games() { ID= "Game10", Text= "Tennis"},
};
public async Task OnFiltering(FilteringEventArgs e)
{
e.PreventDefaultAction = true;
query = new Query().Where(new WhereFilter()
{
Field = "ID",
value = e.Text,
Operator = "startswith",
IgnoreCase = true
});
await this.autoObj.Filter(LocalData, query);
}
} |
The Sample above does not filter by text.
Hi Steven Cramer,
Sorry for the inconvenience. In AutoComplete component, to filter the value using more than one fields, you can use the predicate of DataManager. Please refer to the below code
@using Syncfusion.Blazor.DropDowns @using Syncfusion.Blazor.Data <div class="col-lg-12 control-section"> <div class="control-wrapper"> <label class="example-label">Select a country</label> <SfAutoComplete TValue="string" @ref="AutocompleteObj" TItem="Countries" IgnoreAccent="true" IgnoreCase="true" Placeholder="e.g. Australia" DataSource="@Country"> <AutoCompleteFieldSettings Text="Name" Value="Code" /> <AutoCompleteEvents TValue="string" TItem="Countries" Filtering="OnFilter" /> </SfAutoComplete> </div> </div> @code { private async Task OnFilter(FilteringEventArgs args) { args.PreventDefaultAction = true; var pre = new WhereFilter(); var predicate = new List<WhereFilter>(); predicate.Add(new WhereFilter() { Condition = "or", Field = nameof(Countries.Code), value = args.Text, Operator = "contains", IgnoreAccent = true, IgnoreCase = true }); predicate.Add(new WhereFilter() { Condition = "or", Field = nameof(Countries.Name), value = args.Text, Operator = "contains", IgnoreAccent = true, IgnoreCase = true }); pre = WhereFilter.Or(predicate); var query = new Query().Where(pre); await AutocompleteObj.FilterAsync(Country, query); } } |
Sample: https://blazorplayground.syncfusion.com/BjVgMWBZznRjdTXi
Regards,
Priyanka K