CodeBeamOrg / CodeBeam.MudBlazor.Extensions

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

SearchBox isn't displayed when using RenderFragment instead of ItemCollection #257

Closed MartinSoka closed 10 months ago

MartinSoka commented 10 months ago

Hi, i wanted to disable certain items within MudSelectExtended, hence i switched from ItemCollection to RenderFragment display of elements. However it looks like the SearchBox is usable only with ItemCollection. Is this true? If yes what could i do to disable certain elemnts dynamically within the ItemCollection and add text to them (like in the examples using ItemDisabledTemplate)


    <MudItem xs="12" sm="8" Class="d-flex gap-4">
        <MudSelectExtended  T="string" SearchBox="true" SearchBoxAutoFocus=true SearchBoxClearable=true Label="Standard Search" AnchorOrigin="Origin.BottomCenter" Variant="Variant.Outlined" HelperText="Search with 'Contains' logic"> 
          <ChildContent>
             @foreach (var state in _states)
                {
                    <MudSelectItemExtended Value="state" Disabled=@(state.StartsWith('A') ? true : false)>@state</MudSelectItemExtended>
                }   
          </ChildContent>  
        </MudSelectExtended>
    </MudItem>
</MudGrid>

@code {
    private string[] _states =

    {
        "Alabama", "Alaska", "American Samoa", "Arizona",
        "Arkansas", "California", "Colorado", "Connecticut",
        "Delaware", "District of Columbia", "Federated States of Micronesia",
        "Florida", "Georgia", "Guam", "Hawaii", "Idaho",
        "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky",
        "Louisiana", "Maine", "Marshall Islands", "Maryland",
        "Massachusetts", "Michigan", "Minnesota", "Mississippi",
    };

    private bool SearchItems(string value, string searchString)
    {
        if (searchString == "")
        {
            return true;
        }

        if (value.StartsWith(searchString, StringComparison.CurrentCultureIgnoreCase))
        {
            return true;
        }

        return false;
    }
}```
mckaragoz commented 10 months ago

Yes currently searchbox only possible with ItemCollection approach. You have some options:

  1. Use Combobox (Combobox currently only support renderfragment but also has searchbox like autocomplete)
  2. MudSelectExtended has ItemDisabledFunc so you can determine the logic with ItemCollection
MartinSoka commented 10 months ago

thx for the quick reply @mckaragoz I've used ItemDisabledFunc