(Question) MudSelectExtended with objects instead of strings
dannythunder opened this issue · comments
So. I'm having a list of "switches" (see model below). I want to be able to search in this list an multi select.
I'm close to doing so, but the switches I select doesn't get saved to my selectedSwitches list.
I don't know what I'm missing here.
<MudSelectExtended T="SwitchModel"
Label="Sök switch"
SearchBox="true"
SearchBoxAutoFocus="true"
SearchBoxClearable="true"
SearchFunc="@SearchItems"
MultiSelection="true"
SelectedValues="@selectedSwitches"
ItemCollection="@switchar"
ToStringFunc="@(new Func<SwitchModel, string>(item => item?.Namn))"
Variant="Variant.Outlined">
</MudSelectExtended>
public class SwitchModel
{
public int Id { get; set; }
public string Namn { get; set; }
}
private List<SwitchModel> switchar = new();
private ICollection<SwitchModel> selectedSwitches = new List<SwitchModel>();
private bool SearchItems(SwitchModel item, string searchString)
{
return searchString == "" || item.Namn.Contains(searchString, StringComparison.CurrentCultureIgnoreCase);
}
Right after I posted this, I saw @bind-SelectedValues used IEnumerable (when I tried to use as the Collection that SelectedValues used. So I solved this pretty much after posting....