Unplanned
Last Updated: 01 Jul 2020 08:18 by ADMIN
Svetoslav
Created on: 01 Jul 2020 08:15
Category: DropDownList
Type: Feature Request
3
Add support for disabled items

Hello everyone,

We have opened this Feature Request to gather your insights on the addition of disabled items for the DropDownList.

As a workaround, for the time being, you could use the following code snippet. It would prevent the user from clicking on the item with the mouse, but navigating with the keyboard and selecting it would still work.

<style>
    .disabled-item {
        color: #D3D3D3;
        width:100%;
    }

    /* remove default padding so the user can't click the underlying element outside the template
        Note: this will also affect other dropdowns on the page
    */
    .ddl-item {
        padding: 4px 8px;
    }

    .k-popup ul.k-list li.k-item {
        padding: 0;
    }
</style>

@TheValue
<br />

<TelerikDropDownList Data="@myDdlData" TextField="MyTextField" ValueField="MyValueField" @bind-Value="@TheValue">
    <ItemTemplate>
        @{
            MyDdlModel item = context as MyDdlModel;
            <div @onclick:preventDefault="@item.IsDisabled" 
                 @onclick:stopPropagation="@item.IsDisabled"
                 class="@( item.IsDisabled ? "disabled-item ddl-item" : "ddl-item" )">
                    @item.MyTextField
            </div>
        }
    </ItemTemplate>
</TelerikDropDownList>


@code {
    int TheValue { get; set; } = 2;

    public class MyDdlModel
    {
        public int MyValueField { get; set; }
        public string MyTextField { get; set; }
        public bool IsDisabled { get; set; }
    }

    IEnumerable<MyDdlModel> myDdlData = Enumerable.Range(1, 20).Select(x => new MyDdlModel
    {
        MyTextField = "item " + x,
        MyValueField = x,
        IsDisabled = x % 3 == 0
    });
}

0 comments