Blazor ComboBox Features

    The Ignite UI for Blazor ComboBox component exposes several features such as filtering and grouping.

    Combobox Features Example

    The following demo shows some ComboBox features that are enabled/disabled at runtime:

    EXAMPLE
    MODULES
    DATA
    RAZOR
    CSS

    Like this sample? Get access to our complete Ignite UI for Blazor toolkit and start building your own apps in minutes. Download it for free.

    In our sample we are going to use the IgbSwitch component, so we have to register it together with the combo:

    // in Program.cs file
    
    builder.Services.AddIgniteUIBlazor(typeof(IgbComboModule));
    builder.Services.AddIgniteUIBlazor(typeof(IgbSwitchModule));
    razor

    You will also need to link an additional CSS file to apply the styling to the IgbSwitch component. The following needs to be placed in the wwwroot/index.html file in a Blazor Web Assembly project or the Pages/_Host.cshtml file in a Blazor Server project:

    <link href="_content/IgniteUI.Blazor/themes/light/bootstrap.css" rel="stylesheet" />
    razor
    <IgbCombo 
        Label="Cities" 
        Placeholder="Pick a city" 
        Data="Data" 
        ValueKey="Id" 
        DisplayKey="Name"
        DisableFiltering="@DisableFiltering"
        CaseSensitiveIcon="@CaseSensitiveIcon"
        GroupKey="@Group"
        Disabled="@Disabled">
    </IgbCombo>
    
    <IgbSwitch Change="@OnDisableFilteringClick">Disable Filtering</IgbSwitch>
    <IgbSwitch Change="@OnCaseSensitiveClick" Disabled="@DisableFiltering">Show Case-sensitive Icon</IgbSwitch>
    <IgbSwitch Change="@OnGroupClick">Enable Grouping</IgbSwitch>
    <IgbSwitch Change="@OnDisableClick">Disable Combo</IgbSwitch>
    
    @code {
        private bool DisableFiltering = false;
        private bool CaseSensitiveIcon = false;
        private bool Disabled = false;
    
        public void OnDisableFilteringClick(IgbComponentBoolValueChangedEventArgs e) {
            IgbSwitch sw = e.Parent as IgbSwitch;
            this.DisableFiltering = sw.Checked;
        }
    
        public void OnCaseSensitiveClick(IgbComponentBoolValueChangedEventArgs e) {
            IgbSwitch sw = e.Parent as IgbSwitch;
            this.CaseSensitiveIcon = sw.Checked;
        }
    
        public void OnDisableClick(IgbComponentBoolValueChangedEventArgs e) {
            IgbSwitch sw = e.Parent as IgbSwitch;
            this.Disabled = sw.Checked;
        }
    }
    razor

    Note that grouping is enabled/disabled by setting the GroupKey property to a corresponding data source field:

    @code {
        private string Group = "";
    
        public void OnGroupClick(IgbComponentBoolValueChangedEventArgs e) {
            IgbSwitch sw = e.Parent as IgbSwitch;
            this.Group = sw.Checked ? "Country" : "";
        }
    }
    razor

    Features

    Filtering

    By default, filtering in the ComboBox is enabled. It can be disabled by setting the DisableFiltering property.

    Filtering options can be further enhanced by enabling the search case sensitivity. The case-sensitive icon can be turned on using the CaseSensitiveIcon property so that end-users can control the case sensitivity.

    <IgbCombo DisableFiltering="true" CaseSensitiveIcon="true" />
    razor

    Filtering Options

    The Ignite UI for Blazor ComboBox component exposes one more filtering property that allows passing configuration of both FilterKey and CaseSensitive options. The FilterKey indicates which data source field should be used for filtering the list of options. The CaseSensitive option indicates if the filtering should be case-sensitive or not.

    The following code snippet shows how to filter the cities from our data source by country instead of name. We are also making the filtering case-sensitive by default:

    Grouping

    Defining a GroupKey option will group the items, according to the provided key:

    <IgbCombo GroupKey="region" />
    razor

    The GroupKey property will only have effect if your data source consists of complex objects.

    Sorting Direction

    The ComboBox component also exposes an option for setting whether groups should be sorted in ascending or descending order. By default, the sorting order is ascending:

    <IgbCombo GroupSorting="desc" />
    razor

    Label

    The IgbCombo label can be set easily using the Label property:

    <IgbCombo Label="Cities" />
    razor

    Placeholder

    A placeholder text can be specified for both the ComboBox component input and the search input placed inside the dropdown menu:

    <IgbCombo Placeholder="Pick a city" PlaceholderSearch="Search for a city" />
    razor

    Autofocus

    If you want your ComboBox to be automatically focused on page load you can use the following code:

    <IgbCombo Autofocus="true" />
    razor

    Search Input Focus

    The ComboBox search input is focused by default. To disable this feature and move the focus to the list of options use the AutofocusList property as shown below:

    <IgbCombo AutofocusList="true" />
    razor

    Required

    The ComboBox can be marked as required by setting the required property.

    <IgbCombo Required="true" />
    razor

    Disable ComboBox

    You can disable the ComboBox using the Disabled property:

    <IgbCombo Disabled="true" />
    razor

    Additional Resources