-
Notifications
You must be signed in to change notification settings - Fork 81
Added new kb article treeview-change-expand-collapse-icons #2618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
eb4df7f
735bbc3
90f21b3
cfee3eb
f0e943f
ebbcc33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| --- | ||
| title: Change the Expand and Collapse Icons in TreeView | ||
| description: Learn how to customize the expand and collapse icons in the TreeView component for Blazor. | ||
| type: how-to | ||
| page_title: How to Customize Expand and Collapse Icons in Blazor TreeView | ||
| slug: treeview-kb-change-expand-collapse-icons | ||
| tags: treeview, blazor, icons, expand, collapse, customization | ||
ntacheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| res_type: kb | ||
| ticketid: 1656109 | ||
| --- | ||
|
|
||
| ## Environment | ||
|
|
||
| <table> | ||
| <tbody> | ||
| <tr> | ||
| <td>Product</td> | ||
| <td>TreeView for Blazor</td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
ntacheva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Description | ||
| I want to customize the icons used for expanding and collapsing items in the [TreeView]({%slug treeview-overview%}) for Blazor. | ||
ntacheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| This knowledge base article answers the following questions: | ||
| - How can I use custom icons for the TreeView expand and collapse functionality? | ||
| - Is it possible to change the default expand and collapse icons in the TreeView for Blazor? | ||
|
|
||
| ## Solution | ||
|
|
||
| You can change the expand/collapse icons in the TreeView by overriding the built-in icons with other icons using [custom CSS rules]({%slug themes-override%}). In addition, you can use the `Class` parameter of the TreeView to add a custom CSS Class and modify a specific instance of the TreeView, instead of all instances on the page. | ||
|
|
||
| >caption Change the expand/collapse icons in TreeView | ||
|
|
||
| ````CSHTML | ||
| @* If your Telerik.UI.for.Blazor version is 4.3.0 or later, use the following CSS. *@ | ||
| @* Render the desired SVG icon and inspect it with your dev tools to get its path. *@ | ||
| <style> | ||
| .custom-icons .k-treeview-toggle .k-svg-icon.k-svg-i-caret-alt-down svg path { | ||
| d: path("m382.059 158.059-126.06 126.06-126.061-126.06L96 192l159.999 160L416 192z"); | ||
| } | ||
|
|
||
| .custom-icons .k-treeview-toggle .k-svg-icon.k-svg-i-caret-alt-right svg path { | ||
| d: path("m158.059 129.941 126.06 126.06-126.06 126.061L192 416l160-159.999L192 96z"); | ||
| </style> | ||
|
|
||
| @* If your Telerik.UI.for.Blazor version is below 4.3.0, use this CSS. *@ | ||
ntacheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| @* Copy the unicode of your desired icon from the Progress Design System - https://www.telerik.com/design-system/docs/foundation/iconography/icon-list/ *@ | ||
|
|
||
| @* <style> | ||
| .custom-icons .k-treeview-toggle .k-icon.k-i-caret-alt-down::before { | ||
| content: "\e015"; | ||
| } | ||
|
|
||
| .custom-icons .k-treeview-toggle .k-icon.k-i-caret-alt-right::before { | ||
| content: "\e014"; | ||
| } | ||
| </style> *@ | ||
|
Comment on lines
+51
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can mention / show what to do to if one wants to use non-Telerik font icons. They will also have to override the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can add that on later stage if there is a demand/questions. |
||
|
|
||
| <TelerikTreeView Class="custom-icons" | ||
| Data="@FlatData" | ||
| @bind-ExpandedItems="@ExpandedItems" /> | ||
|
|
||
| @code { | ||
| private IEnumerable<TreeItem> FlatData { get; set; } | ||
|
|
||
| private IEnumerable<object> ExpandedItems { get; set; } = new List<TreeItem>(); | ||
|
|
||
| protected override void OnInitialized() | ||
| { | ||
| FlatData = GetFlatData(); | ||
|
|
||
| ExpandedItems = FlatData.Where(x => x.HasChildren == true).ToList(); | ||
ntacheva marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| List<TreeItem> GetFlatData() | ||
| { | ||
| List<TreeItem> items = new List<TreeItem>(); | ||
|
|
||
| items.Add(new TreeItem() | ||
| { | ||
| Id = 1, | ||
| Text = "wwwroot", | ||
| ParentId = null, | ||
| HasChildren = true, | ||
| Icon = SvgIcon.Folder | ||
| }); | ||
| items.Add(new TreeItem() | ||
| { | ||
| Id = 2, | ||
| Text = "css", | ||
| ParentId = 1, | ||
| HasChildren = true, | ||
| Icon = SvgIcon.Folder | ||
| }); | ||
| items.Add(new TreeItem() | ||
| { | ||
| Id = 3, | ||
| Text = "js", | ||
| ParentId = 1, | ||
| HasChildren = true, | ||
| Icon = SvgIcon.Folder | ||
| }); | ||
| items.Add(new TreeItem() | ||
| { | ||
| Id = 4, | ||
| Text = "site.css", | ||
| ParentId = 2, | ||
| Icon = SvgIcon.Css | ||
| }); | ||
| items.Add(new TreeItem() | ||
| { | ||
| Id = 5, | ||
| Text = "scripts.js", | ||
| ParentId = 3, | ||
| Icon = SvgIcon.Js | ||
| }); | ||
|
|
||
| return items; | ||
| } | ||
|
|
||
| public class TreeItem | ||
| { | ||
| public int Id { get; set; } | ||
| public string Text { get; set; } | ||
| public int? ParentId { get; set; } | ||
| public bool HasChildren { get; set; } | ||
| public ISvgIcon Icon { get; set; } | ||
| } | ||
| } | ||
| ```` | ||
| ## See Also | ||
| - [TreeView Overview]({%slug treeview-overview%}) | ||
| - [Telerik Icons List](https://www.telerik.com/design-system/docs/foundation/iconography/icon-list/) | ||
Uh oh!
There was an error while loading. Please reload this page.