<SfComboBox @ref="comboboxObj" TItem="Countries" TValue="string" @bind-Value="Value" Placeholder="e.g. Australia" DataSource="@Country" AllowFiltering="true">
<ComboBoxFieldSettings Text="Name" Value="Code"></ComboBoxFieldSettings>
<ComboBoxEvents TValue="string" Filtering="onFiltering"></ComboBoxEvents>
<ComboBoxTemplates TItem="Countries">
<NoRecordsTemplate>
<div>
<div id="nodata"> No matched item, do you want to add it as new item in list?</div>
<button id="btn" class="e-control e-btn" @onclick="@UpdateValue">Add New Item</button>
</div>
</NoRecordsTemplate>
</ComboBoxTemplates>
</SfComboBox>
@code { List<Countries> Country = new List<Countries>
{
new Countries() { Name = "Australia", Code = "AU" },
new Countries() { Name = "Bermuda", Code = "BM" },
new Countries() { Name = "Canada", Code = "CA" },
new Countries() { Name = "Cameroon", Code = "CM" },
};
public void onFiltering(FilteringEventArgs e)
{
Text = e.Text;
}
public void UpdateValue()
{
this.comboboxObj.AddItem(new List<Countries> { new Countries() { Name = Text, Code = Text } });
this.comboboxObj.HidePopup();
}
}
|
<SfListBox TValue="string[]" TItem="DataValues" @ref="ListboxObj">
<ListBoxFieldSettings Text="Text" Value="Id"></ListBoxFieldSettings>
<ListBoxTemplates TItem="DataValues">
<NoRecordsTemplate>
<div id="nodata">
No data have been registered
<SfButton @onclick="UpdateValue">Data</SfButton>
</div>
</NoRecordsTemplate>
</ListBoxTemplates>
</SfListBox>
@code
{
public SfListBox<string[], DataValues> ListboxObj;
private List<DataValues> Data = new List<DataValues>
{
new DataValues { Text = "Hennessey Venom", Id = "List-01" },
new DataValues { Text = "Bugatti Chiron", Id = "List-02" },
};
public class DataValues
{
public string Text { get; set; }
public string Id { get; set; }
}
private async Task UpdateValue()
{
await ListboxObj.AddItem(Data);
}
}
|