Item Template

14 Dec 20244 minutes to read

The ItemTemplate property in the DropDownButton component allows for the definition of custom templates to display dropdown items. This feature is especially useful for customizing the appearance and layout of dropdown items beyond the default options provided. By utilizing this property, diverse content such as icons, formatted text, and other visual elements can be integrated into the dropdown items for a more engaging and tailored user interface.

<ejs-dropdownbutton id="separator" content="Edit" items="ViewBag.items" iconCss="e-icons e-edit" itemTemplate="#itemTemplate"></ejs-dropdownbutton>


<script id="itemTemplate" type="text/x-template">
${if(url)}
<div>
  <span class="e-menu-icon ${iconCss}"></span>
  <a href="${url}" target="_blank">
      <span class="custom-class">${text}</span>
  </a>
 </div>
${else}
  <div>
      <span class="e-menu-icon ${iconCss}"></span>
      <span class="custom-class">${text}</span>
  </div>
${/if}
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace WebApplication1.Controllers
{
    public class DropDownButtonController : Controller
    {
        public ActionResult Template()
        {
            List<object> items = new List<object>();
            items.Add(new
            {
                text = 'Home',
                iconCss = 'e-icons e-home'
            });
            items.Add(new
            {
                text = 'Search',
                iconCss = 'e-icons e-search',
                url = 'http://www.google.com'
            });
            items.Add(new
            {
                text = 'Yes / No',
                iconCss = 'e-icons e-check-box'
            });
            items.Add(new
            {
                text = 'Text',
                iconCss = 'e-icons e-caption',
            });
            items.Add(new
            {
                separator = "True"
            });
            items.Add(new
            {
                text = 'Syncfusion',
                iconCss = 'e-icons e-mouse-pointer',
                url = 'http://www.syncfusion.com'
            });
            ViewBag.items = items;
            return View();
        }
    }
}

Drop Down Button template