|
| 1 | +--- |
| 2 | +title: Hierarchy |
| 3 | +page_title: Hierarchy |
| 4 | +description: "Find out how to create an item hierarchy using the Telerik UI Drawer HtmlHelper for {{ site.framework }}." |
| 5 | +slug: hierarchy_drawer_aspnetcore |
| 6 | +position: 6 |
| 7 | +--- |
| 8 | + |
| 9 | +# Hierarchy |
| 10 | + |
| 11 | +The Kendo UI Drawer provides the built-in functionality to create a hierarchical structure. Visit the [Hierarchy demo](https://demos.telerik.com/{{ site.platform }}/drawer/hierarchy) for a live example. |
| 12 | + |
| 13 | +## Configuration |
| 14 | + |
| 15 | +To utilize the hierarchy functionality of the Telerik UI Drawer: |
| 16 | + |
| 17 | +1. Add list elements with data-role attribute `drawer-item` and class `hidden` to the drawer's `Template` configuration. |
| 18 | + |
| 19 | + ```Razor |
| 20 | + @(Html.Kendo().Drawer() |
| 21 | + .Name("drawer") |
| 22 | + .Template(@" |
| 23 | + <ul> |
| 24 | + <li data-role='drawer-item' class='k-state-selected'><span class='k-icon k-i-information'></span><span class='k-item-text' data-id='GettingStarted'>Getting Started</span><span class='k-spacer'></span><span class='k-icon k-i-arrow-chevron-right'></span></li> |
| 25 | + <li data-role='drawer-separator'></li> |
| 26 | + <li data-role='drawer-item' class='hidden'><span class='k-icon k-i-none'></span><span class='k-icon k-i-question'></span><span class='k-item-text' data-id='Kendo'>About Kendo UI</span></li> |
| 27 | + <li data-role='drawer-item' class='hidden'><span class='k-icon k-i-none'></span><span class='k-icon k-i-palette'></span><span class='k-item-text' data-id='ThemeSupport'>Supported Themes</span></li> |
| 28 | + <li data-role='drawer-separator'></li> |
| 29 | + <li data-role='drawer-item'><span class='k-icon k-i-zoom'></span><span class='k-item-text' data-id='Overview'>Overview</span><span class='k-spacer'></span><span class='k-icon k-i-arrow-chevron-right'></li> |
| 30 | + <li data-role='drawer-item' class='hidden'><span class='k-icon k-i-none'></span><span class='k-icon k-i-js'></span><span class='k-item-text' data-id='About'>About Kendo</span></li> |
| 31 | + <li data-role='drawer-item' class='hidden'><span class='k-icon k-i-none'></span><span class='k-icon k-i-style-builder'></span><span class='k-item-text' data-id='All'>All Kendo Components</span></li> |
| 32 | + <li data-role='drawer-separator'></li> |
| 33 | + <li data-role='drawer-item'><span class='k-icon k-i-star'></span><span class='k-item-text' data-id='Popular'>Most popular components</span></li> |
| 34 | + </ul> |
| 35 | + ") |
| 36 | + ) |
| 37 | + ``` |
| 38 | +
|
| 39 | +1. Add the `ItemClick` event handler to the drawer's configuration. |
| 40 | +
|
| 41 | + ```Razor |
| 42 | + @(Html.Kendo().Drawer() |
| 43 | + .Name("drawer") |
| 44 | + .Events(x => x.ItemClick("onItemClick")) |
| 45 | + ) |
| 46 | + ``` |
| 47 | +
|
| 48 | +1. Define the `onItemClick` handling function. |
| 49 | +
|
| 50 | + ```html |
| 51 | + <script> |
| 52 | + function onItemClick(e) { |
| 53 | + if (!e.item.hasClass("k-drawer-separator")) { |
| 54 | + var drawerContainer = e.sender.drawerContainer; |
| 55 | + var expandIcon = e.item.find("span.k-i-arrow-chevron-right"); |
| 56 | + var collapseIcon = e.item.find("span.k-i-arrow-chevron-down"); |
| 57 | + drawerContainer.find("#drawer-content > div").addClass("hidden"); |
| 58 | + drawerContainer.find("#drawer-content").find("#" + e.item.find(".k-item-text").attr("data-id")).removeClass("hidden"); |
| 59 | +
|
| 60 | + /* If the expandIcon is visible, the sub-items are hidden. Clicking on the icon should remove the hidden class and reveal the items.*/ |
| 61 | + if (expandIcon.length) { |
| 62 | + e.item.nextAll(".k-drawer-item:not(.k-drawer-separator):lt(2)").removeClass("hidden"); |
| 63 | + expandIcon.removeClass("k-i-arrow-chevron-right").addClass("k-i-arrow-chevron-down"); |
| 64 | + } |
| 65 | +
|
| 66 | + /* If the collapseIcon is visible, the sub-items are visible. Clicking on the icon should add the hidden class and hide the items. */ |
| 67 | + if (collapseIcon.length) { |
| 68 | + e.item.nextAll(".k-drawer-item:not(.k-drawer-separator):lt(2)").addClass("hidden"); |
| 69 | + collapseIcon.addClass("k-i-arrow-chevron-right").removeClass("k-i-arrow-chevron-down"); |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + </script> |
| 74 | + ``` |
| 75 | +
|
| 76 | +## See Also |
| 77 | +
|
| 78 | +* [Hierarchy by the Drawer HtmlHelper for {{ site.framework }} (Demo)](https://demos.telerik.com/{{ site.platform }}/drawer/hierarchy) |
| 79 | +* [Server-Side API](/api/drawer) |
0 commit comments