Example of Icons and Images in ASP.NET MVC DropDownTree Control
This sample explains you about the Dropdown Tree item that can be configured by the icons or images. Click on the icon or double click on it to expand or collapse and to show the icons or images that are configured with the items.
@Html.UiDropDownTree("ddt", new UiDropDownTreeOptions
{
Placeholder = "Select a folder or file",
PopupHeight = "200px",
DataSource = (IEnumerable<DropdownsDemoController.DropDownTreeIcons>)ViewData["data"],
Fields = new UiDropDownFields { Value = "nodeId", Text = "nodeText", IconCss = "icon", ImageUrl = "image", Expanded = "expanded", Child = "child" }
})
<style>
.control-section .content { margin: 0 auto; width: 250px; }
.control-section h4 { margin: 0 0 8px; }
.control-section .folder, .control-section .docx, .control-section .pdf, .control-section .ppt, .control-section .exe, .control-section .zip,
.control-section .audio, .control-section .video, .control-section .images,
.ui-dd-popup .folder, .ui-dd-popup .docx, .ui-dd-popup .pdf, .ui-dd-popup .ppt, .ui-dd-popup .exe, .ui-dd-popup .zip,
.ui-dd-popup .audio, .ui-dd-popup .video, .ui-dd-popup .images {
display: inline-block; width: 14px; height: 14px; background-color: currentColor;
-webkit-mask: no-repeat center / contain; mask: no-repeat center / contain;
-webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.1'%3E%3Cpath d='M4 1.8h5l3.5 3.5V14H4zM9 1.8v3.5h3.5'/%3E%3C/svg%3E");
mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.1'%3E%3Cpath d='M4 1.8h5l3.5 3.5V14H4zM9 1.8v3.5h3.5'/%3E%3C/svg%3E");
}
.control-section .folder, .ui-dd-popup .folder {
-webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z'/%3E%3C/svg%3E");
mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z'/%3E%3C/svg%3E");
}
</style>
@using Lumen.UI.Mvc.Demo.Controllers
<div class="control-section">
<div class="content" style="padding-top:75px">
@Html.UiDropDownTree("ddt", new UiDropDownTreeOptions
{
Placeholder = "Select a folder or file",
PopupHeight = "200px",
DataSource = (IEnumerable<DropdownsDemoController.DropDownTreeIcons>)ViewData["data"],
Fields = new UiDropDownFields { Value = "nodeId", Text = "nodeText", IconCss = "icon", ImageUrl = "image", Expanded = "expanded", Child = "child" }
})
</div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class DropDownTreeController : Controller
{
// The page is Views/DropDownTree/IconsAndImages.cshtml; it draws what ViewData holds.
public ActionResult IconsAndImages()
{
ViewData["data"] = new DropDownTreeIcons().getIconsData();
return View();
}
public class Employees
{
public string Name { get; set; }
public string Eimg { get; set; }
public string Designation { get; set; }
public string Country { get; set; }
public List<Employees> EmployeesList()
{
List<Employees> emp = new List<Employees>();
emp.Add(new Employees { Name= "Andrew Fuller", Eimg= "7", Designation = "Team Lead", Country= "England"});
emp.Add(new Employees { Name= "Anne Dodsworth", Eimg= "1", Designation = "Developer", Country= "USA"});
emp.Add(new Employees { Name= "Janet Leverling", Eimg= "3", Designation = "HR", Country= "USA"});
emp.Add(new Employees { Name= "Laura Callahan", Eimg= "2", Designation = "Product Manager", Country= "USA"});
emp.Add(new Employees { Name= "Margaret Peacock", Eimg= "6", Designation = "Developer", Country= "USA"});
emp.Add(new Employees { Name= "Michael Suyama", Eimg= "9", Designation = "Team Lead", Country= "USA"});
emp.Add(new Employees { Name= "Nancy Davolio", Eimg= "4", Designation = "Product Manager", Country= "USA"});
emp.Add(new Employees { Name= "Robert King", Eimg= "8", Designation = "Developer ", Country= "England"});
emp.Add(new Employees { Name= "Steven Buchanan", Eimg= "10", Designation = "CEO", Country= "England" });
return emp;
}
}
public class DropDownTreeIcons
{
public string nodeId { get; set; }
public string nodeText { get; set; }
public string icon { get; set; }
public bool expanded { get; set; }
public List<ChildItems> child { get; set; }
public List<DropDownTreeIcons> getIconsData()
{
List<DropDownTreeIcons> Parent = new List<DropDownTreeIcons>();
List<ChildItems> Child1 = new List<ChildItems>();
Parent.Add(new DropDownTreeIcons { nodeId = "01", nodeText = "Music", icon = "folder", child = Child1, });
Child1.Add(new ChildItems { nodeId = "01-01", nodeText = "Gouttes.mp3", icon = "audio" });
List<ChildItems> Child2 = new List<ChildItems>();
Parent.Add(new DropDownTreeIcons { nodeId = "02", nodeText = "Videos", icon = "folder", child = Child2, });
Child2.Add(new ChildItems { nodeId = "02-01", nodeText = "Naturals.mp4", icon = "video" });
Child2.Add(new ChildItems { nodeId = "02-02", nodeText = "Wild.mpeg", icon = "video" });
List<ChildItems> Child3 = new List<ChildItems>();
Parent.Add(new DropDownTreeIcons { nodeId = "03", nodeText = "Documents", icon = "folder", child = Child3, });
Child3.Add(new ChildItems { nodeId = "03-01", nodeText = "Environment Pollution.docx", icon = "docx" });
Child3.Add(new ChildItems { nodeId = "03-02", nodeText = "Global Water, Sanitation, & Hygiene.docx", icon = "docx" });
Child3.Add(new ChildItems { nodeId = "03-03", nodeText = "Global Warming.ppt", icon = "ppt" });
Child3.Add(new ChildItems { nodeId = "03-04", nodeText = "Social Network.pdf", icon = "pdf" });
Child3.Add(new ChildItems { nodeId = "03-05", nodeText = "Youth Empowerment.pdf", icon = "pdf" });
List<ChildItems> Child4 = new List<ChildItems>();
List<SubChildItems> SubChildren = new List<SubChildItems>();
Parent.Add(new DropDownTreeIcons { nodeId = "04", nodeText = "Pictures", icon = "folder", child = Child4, expanded = true, });
Child4.Add(new ChildItems { nodeId = "04-01", nodeText = "Camera Roll", icon = "folder", child = SubChildren, expanded = true });
SubChildren.Add(new SubChildItems { nodeId = "04-01-01", nodeText = "WIN_20160726_094117.JPG", image = "/Content/treeview/images/Employees/2.png" });
SubChildren.Add(new SubChildItems { nodeId = "04-01-02", nodeText = "WIN_20160726_094118.JPG", image = "/Content/treeview/images/Employees/9.png" });
Child4.Add(new ChildItems { nodeId = "04-02", nodeText = "Wind.jpg", icon = "images" });
Child4.Add(new ChildItems { nodeId = "04-03", nodeText = "Stone.jpg", icon = "images" });
List<ChildItems> Child5 = new List<ChildItems>();
Parent.Add(new DropDownTreeIcons { nodeId = "04", nodeText = "Downloads", icon = "folder", child = Child5, });
Child5.Add(new ChildItems { nodeId = "04-01", nodeText = "UI-Guide.pdf", icon = "pdf" });
Child5.Add(new ChildItems { nodeId = "04-02", nodeText = "Tutorials.zip", icon = "zip" });
Child5.Add(new ChildItems { nodeId = "04-03", nodeText = "Game.exe", icon = "exe" });
Child5.Add(new ChildItems { nodeId = "04-04", nodeText = "TypeScript.7z", icon = "zip" });
return Parent;
}
}
public class ChildItems
{
public string nodeId { get; set; }
public string nodeText { get; set; }
public string icon { get; set; }
public bool expanded { get; set; }
public List<SubChildItems> child { get; set; }
}
public class SubChildItems
{
public string nodeId { get; set; }
public string nodeText { get; set; }
public string icon { get; set; }
public bool expanded { get; set; }
public string image { get; set; }
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
The Dropdown Tree control has the built-in option to customize each item's appearance with the icons and images by mapping the IconCss and imageUrl fields.
In this demo, the Dropdown Tree is showcased like a file system with custom icons and images.