Disabled Items in ASP.NET CORE ComboBox Control

19 Jun 20243 minutes to read

The ComboBox provides options for individual items to be either in an enabled or disabled state for specific scenarios. The category of each list item can be mapped through the disabled field in the data table. Once an item is disabled, it cannot be selected as a value for the component. To configure the disabled item columns, use the fields.disabled property.

In the following sample, State are grouped according on its category using disabled field.

@{
    List<DisableStatusData> status = new List<DisableStatusData>();
            status.Add(new DisableStatusData() { Status = "Open", State= false });
            status.Add(new DisableStatusData() { Status = "Waiting for Customer", State= false });
            status.Add(new DisableStatusData() { Status = "On Hold", State= true });
            status.Add(new DisableStatusData() { Status = "Follow-up", State= false });
            status.Add(new DisableStatusData() { Status = "Closed", State= true });
            status.Add(new DisableStatusData() { Status = "Solved", State= false });
            status.Add(new DisableStatusData() { Status = "Feature Request", State= false });    
}
<div id='groupList' class='col-lg-6' style='padding-top:15px'>
    <div class='content'>
        <ejs-combobox id="status" placeholder="Select Status" popupHeight="200px" dataSource="@status">
            <e-combobox-fields value="Status" disabled="State" ></e-combobox-fields>
        </ejs-combobox>
    </div>
</div>
public class DisableStatusData
{
    public string Status { get; set; }
    public bool State { get; set; }
}

Disable Item Method

The disableItem method can be used to handle dynamic changing in disable state of a specific item. Only one item can be disabled in this method. To disable multiple items, this method can be iterated with the items list or array. The disabled field state will to be updated in the dataSource, when the item is disabled using this method. If the selected item is disabled dynamically, then the selection will be cleared.

Parameter Type Description
itemHTMLLIElement HTMLLIElement It accepts the HTML Li element of the item to be removed.
itemValue string | number | boolean | object It accepts the string, number, boolean and object type value of the item to be removed.
itemIndex number It accepts the index of the item to be removed.

Enabled

If you want to disabled the overall component to set the enabled property to false.

Disabled ComboBox Component