CodeBeamOrg / CodeBeam.MudBlazor.Extensions

Useful third party extension components for MudBlazor, from the contributors.
https://mudextensions.codebeam.org/
MIT License
348 stars 60 forks source link

(Question) MudSelectExtended with objects instead of strings #356

Closed dannythunder closed 2 months ago

dannythunder commented 2 months ago

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);
 }
dannythunder commented 2 months ago

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....