|
<SfDropDownList @ref="DDLObj" TItem="GameFields" TValue="string" AllowFiltering="true" Query="@Query" PopupHeight="230px" Index="2" Placeholder="Select a game" @bind-Value="@DropVal" DataSource="@Games">
<DropDownListEvents TValue="string" Filtering="OnFiltering"></DropDownListEvents>
<DropDownListFieldSettings Text="Text" Value="ID"></DropDownListFieldSettings>
</SfDropDownList>
@code {
SfDropDownList<string, GameFields> DDLObj;
public Query Query = new Query().Take(3);
public class GameFields
{
public string ID { get; set; }
public string Text { get; set; }
}
private List<GameFields> Games = new List<GameFields>() {
new GameFields(){ ID= "Game1", Text= "American Football" },
new GameFields(){ ID= "Game2", Text= "Badminton" },
new GameFields(){ ID= "Game3", Text= "Basketball" },
new GameFields(){ ID= "Game4", Text= "Cricket" },
new GameFields(){ ID= "Game5", Text= "Football" },
new GameFields(){ ID= "Game6", Text= "Golf" },
new GameFields(){ ID= "Game7", Text= "Hockey" },
new GameFields(){ ID= "Game8", Text= "Rugby"},
new GameFields(){ ID= "Game9", Text= "Snooker" },
new GameFields(){ ID= "Game10", Text= "Tennis"},
};
public string DropVal;
public string ChangeValue { get; set; } = "Basketball";
public void OnFiltering(FilteringEventArgs args)
{
args.PreventDefaultAction = true;
var query = new Query();
if (args.Text != "")
{
query = new Query().Where(new WhereFilter()
{
Field = "Text",
value = args.Text,
Operator = "startswith",
IgnoreCase = true
});
} else
{
query = new Query().Take(3);
}
this.DDLObj.Filter(Games, query);
}
} |