Custom Node Content
You can customize the content of the TreeView nodes using the formatItem event. The event handler parameters include the element that represents the node and the data item being rendered.
The example below uses the formatItem event to add a "new" badge to the right of new items on the tree.
Electronics
Trimmers/Shavers
Tablets
Phones
Apple
Motorola

Nokia
Samsung
Speakers

Monitors
Toys
Shopkins
Train Sets
Science Kit

Play-Doh
Crayola
Home
Coffeee Maker
Breadmaker

Solar Panel

Work Table
Propane Grill
1 2 3 4 5 6 7 8 9 10 11 12 | // This file locates: "Scripts/Lesson/C1Nav/CustomContent.js". c1.documentReady(function () { var tree = wijmo.Control.getControl( '#theTree' ); tree.formatItem.addHandler(function (s, e) { if (e.dataItem.NewItem) { var imgUrl = newImageUrl; e.element.innerHTML += '<img class="new-icon" src="' + imgUrl + '">' ; } }); }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | // This file locates: "Content/css/Lesson/C1Nav/CustomContent.css". . new -icon { margin-left: 12px; transform: rotate(-30deg); } /* default trees on this sample */ .demo-control .wj-treeview { display:block; height: 350px; font-size: 120%; margin-bottom: 8px; padding: 6px; background: #f0f0f0; box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 | using System.Web.Mvc; namespace LearnMvcClient.Controllers { public partial class C1NavController : Controller { // GET: CustomContent public ActionResult CustomContent() { return View(Models.TreeViewData.GetData(Url)); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | @model IEnumerable< TreeViewData > @section Scripts{ <script> var newImageUrl = '@Href("~/Content/images/new.png")' ; </script> } < h1 > @Html .Raw(Resources.C1Nav.CustomContent_Title) </ h1 > < p > @Html .Raw(Resources.C1Nav.CustomContent_Text1) </ p > < p > @Html .Raw(Resources.C1Nav.CustomContent_Text2) </ p > @Html .C1().TreeView().Id( "theTree" ).Bind(Model).DisplayMemberPath( "Header" ).ChildItemsPath( "Items" ) |