How to add trash can button option against each option of dropdownlist

1 Answer 525 Views
Button DropDownList
Vaibhav
Top achievements
Rank 1
Iron
Vaibhav asked on 17 Oct 2022, 07:27 PM

Hi, 

I need to add a trash can against each option of the dynamic dropdown list. 

example:

How can this be achieved?

What I have achieved so far: 

Dynamically populating the list.

Thanks,

VM

1 Answer, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 20 Oct 2022, 11:27 AM

Hi Vaibhav,

Thank you for reaching out.

I noticed that there is not a Telerik UI for ASP.NET Core license associated with your account which limits the availability of our support services for the product. In this regard, It is recommended that you either purchase or renew your license in order to gain access to the latest updates, fixes, features, and support regarding the Telerik UI for ASP.NET Core components. More information regarding the currently available plans can be reviewed here:

Support Plans

Nevertheless, you can embed any arbitrary HTML markup within the options of the DropDownList by specifying a template similarly to how it is illustrated within the following demo:

Customizing Templates - open the "View Source" tab to observe the utilized configuration.

That being said, for your scenario, in order to embed a button with a trash icon within the DropDownList options, you could try the following approach:

  • Within the .TemplateId() API configuration, specify an id that would point to an external template:
.TemplateId("myTemplate")
  • Within the external template, integrate a separate button whilst utilizing some of our available web-font icons:
<script type="text/html" id="myTemplate">
    #: data.ContactName # 
    <button class="k-button k-button-md k-rounded-md k-button-solid k-button-solid-base" style="float:right;">
        <span  class='k-icon k-i-trash mt-1' style="color:red;"></span>
    </button>
</script>    
  • Set the span element that wraps the template’s total width to 100% of its containing block by accessing it through the generated classes by Kendo. This would be required in order to float the button to the inner end of the container afterwards.
<style>
    #{id of dropdownlist}-list .k-list-item-text {
        min-width:100%
    }
</style> 
  • Right-align the button by applying the "float:right" CSS Rule (highlighted in green).

This would produce the following result:

For your convenience, here is a Telerik REPL that tackles this approach:

Telerik REPL for ASP.NET Core Example

In addition, if you wish to remove a particular item, I might also recommend reviewing the following knowledge base article that could be helpful for your scenario:

Remove DropDownList Items

I hope this helps.

Kind Regards,
Alexander
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Button DropDownList
Asked by
Vaibhav
Top achievements
Rank 1
Iron
Answers by
Alexander
Telerik team
Share this question
or