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:
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));
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" />
<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;
}
}
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" : "";
}
}
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" />
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" />
[!Note] 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" />
Label
The IgbCombo
label can be set easily using the Label
property:
<IgbCombo Label="Cities" />
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" />
Autofocus
If you want your ComboBox to be automatically focused on page load you can use the following code:
<IgbCombo Autofocus="true" />
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" />
Required
The ComboBox can be marked as required by setting the required property.
<IgbCombo Required="true" />
Disable ComboBox
You can disable the ComboBox using the Disabled
property:
<IgbCombo Disabled="true" />