This question is locked. New answers and comments are not allowed.
Is it possible to add your own content (for example action links) to the TreeView leaf? I noticed that TreeViewItem (?) has Content, but I wasn't able to use it. If this is possible, would it be possible to have few lines long example? Thanks
-Tatu
-Tatu
14 Answers, 1 is accepted
0
Hello Tatu,
We didn't manage to implement this functionality for the Q1 beta, yet we're currently developing it and it will be available with the official release.
Sincerely yours,
Alex Gyoshev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
We didn't manage to implement this functionality for the Q1 beta, yet we're currently developing it and it will be available with the official release.
Sincerely yours,
Alex Gyoshev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Kevin Watkins
Top achievements
Rank 1
answered on 31 Mar 2010, 02:33 PM
Hi,
This didn't make it in did it? I need to have arbitrary HTML in my treeview leaves and can't find a way to do it. I can use the content property on the parent nodes and then loop through the children building my own content but that seems overkill. And I can't use the Text property as that escapes my HTML. Any way to do this?
Kev
This didn't make it in did it? I need to have arbitrary HTML in my treeview leaves and can't find a way to do it. I can use the content property on the parent nodes and then loop through the children building my own content but that seems overkill. And I can't use the Text property as that escapes my HTML. Any way to do this?
Kev
0
Hello Kevin,
We did mean the .Content property. I couldn't understand what you are trying to achieve - could you please elaborate?
All the best,
Alex Gyoshev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
We did mean the .Content property. I couldn't understand what you are trying to achieve - could you please elaborate?
All the best,
Alex Gyoshev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Kevin Watkins
Top achievements
Rank 1
answered on 06 Apr 2010, 11:46 AM
Hi,
Sorry let me give a better explanation. Basically I want an equivalent of the Text property that allows arbitrary HTML; I can't see a way to do this currently. Text escapes HTML. Content doesn't work; it adds a new child node. For example say I wanted the leaf nodes in my tree to have bold text:
Doesn't work because the leaves are displayed with no text but a plus icon to expand which reveals the leaf name. My current workaround is something like this:
Which kind of defeats the point of having the Children binder...
What I'd like I guess is an item.Html property I can use instead of item.Text. And what I'd really like is an equivalent of the Content property but just for the text, so I could do things like create action links on the fly and use them in the node name.
Cheers,
Kev
Sorry let me give a better explanation. Basically I want an equivalent of the Text property that allows arbitrary HTML; I can't see a way to do this currently. Text escapes HTML. Content doesn't work; it adds a new child node. For example say I wanted the leaf nodes in my tree to have bold text:
| <% Html.Telerik().TreeView() |
| .Name("Example") |
| .BindTo(Model, mappings => |
| { |
| mappings.For<Node>(binding => binding |
| .ItemDataBound((item, node) => |
| { |
| item.Text = node.Name; |
| item.Expanded = true; |
| }) |
| .Children(node => node.Leaves)); |
| mappings.For<Leaf>(binding => binding |
| .ItemDataBound((item, leaf) => |
| { |
| item.Content = () => |
| { %> |
| <strong><%= leaf.Name %></strong> |
| <% }; |
| })); |
| }).Render(); %> |
Doesn't work because the leaves are displayed with no text but a plus icon to expand which reveals the leaf name. My current workaround is something like this:
| <% Html.Telerik().TreeView() |
| .Name("Example") |
| .BindTo(Model, mappings => |
| { |
| mappings.For<Node>(binding => binding |
| .ItemDataBound((item, node) => |
| { |
| item.Text = node.Name; |
| item.Expanded = true; |
| item.Content = () => |
| { %> |
| <ul> <% |
| foreach(var leaf in node.Leaves) |
| { %> |
| <li><strong><%= leaf.Name %></strong></li> |
| <% } %> |
| </ul> |
| <% }; |
| })); |
| }).Render(); %> |
Which kind of defeats the point of having the Children binder...
What I'd like I guess is an item.Html property I can use instead of item.Text. And what I'd really like is an equivalent of the Content property but just for the text, so I could do things like create action links on the fly and use them in the node name.
Cheers,
Kev
0
Hello Kevin,
Thank you for the explanation. Now that the requirement is clear, what do you find more intuitive? We can
Either way, until the property is implemented, you can override the Text method in TreeViewHtmlBuilder (derived from NavigationHtmlBuilderBase) to use LiteralNode rather than TextNode:
return new LiteralNode(Component.GetItemText(item, ActionMethodCache));
Kind regards,
Alex Gyoshev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Thank you for the explanation. Now that the requirement is clear, what do you find more intuitive? We can
- an Encoded property, which will toggle between encoded and non-encoded Text
- a Template property, which will allow you to format the text in some way that you want - like
.Template = (item) => String.Format("<strong>{0}</strong>", item.Text);
Either way, until the property is implemented, you can override the Text method in TreeViewHtmlBuilder (derived from NavigationHtmlBuilderBase) to use LiteralNode rather than TextNode:
return new LiteralNode(Component.GetItemText(item, ActionMethodCache));
Kind regards,
Alex Gyoshev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Kevin Watkins
Top achievements
Rank 1
answered on 08 Apr 2010, 11:17 AM
Hi,
I don't mind to be honest. Encoded = false might be a better idea for a consistency with the other MVC components. (The grid uses that in columns for example)
Thanks,
Kev
I don't mind to be honest. Encoded = false might be a better idea for a consistency with the other MVC components. (The grid uses that in columns for example)
Thanks,
Kev
0
Hello Kevin,
Done. The property will be available in all upcoming internal builds / service packs / releases.
Greetings,
Alex Gyoshev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Done. The property will be available in all upcoming internal builds / service packs / releases.
Greetings,
Alex Gyoshev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Kevin Watkins
Top achievements
Rank 1
answered on 12 Apr 2010, 11:00 AM
One thing to note is that node names aren't escaped when the nodes are rendered client side, i.e. from a load on demand request. Which is good for me but does mean an inconsistency between how nodes are rendered on server and client sides. Perhaps you can make the Encoding property work on the client side too?
Cheers,
Kev
Cheers,
Kev
0
Hello Kevin,
Done! Thank you for the great feedback.
All the best,
Alex Gyoshev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Done! Thank you for the great feedback.
All the best,
Alex Gyoshev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Tx3
Top achievements
Rank 1
answered on 03 May 2010, 06:49 AM
Hi,
I would like to know current situation of adding your own content to the TreeView leaves. Is this Encoded property implemented, if not then what is the timetable?
I have little bit problems of overriding Text method.. I tried to override it like this, but I get "No suitable member found to override". Am I doing it incorrectly?
public class MyTreeViewHtmlBuilder : TreeViewHtmlBuilder
{
public override IHtmlNode Text(TreeViewItem item)
{
..
}
}
Thanks,
-Tatu
0
Accepted
Hello Tatu,
The Encoded method has been implemented in the Q1 2010 SP1 release (assembly version 2010.1.416). You should be able to download it from your telerik account.
All the best,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
The Encoded method has been implemented in the Q1 2010 SP1 release (assembly version 2010.1.416). You should be able to download it from your telerik account.
All the best,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Tx3
Top achievements
Rank 1
answered on 03 May 2010, 12:20 PM
Thanks, that did the trick!
0
Courtney Mills
Top achievements
Rank 1
answered on 09 Jun 2010, 04:39 PM
I am also trying to put custom content into the treeview using the .Text property and .Encoded = false. However, when I post the page, I get:
Server Error in '/' Application.
Apparently, the control puts the contents of the .Text property of the TreeViewItem into hidden form fields, presumably to maintain state. If so, can this behavior be changed to disable state, or to store it in the session instead?
Thanks!
Server Error in '/' Application.
A potentially dangerous Request.Form value was detected from the client (itemValue="...nvitation <a class="AddPropert...").
Apparently, the control puts the contents of the .Text property of the TreeViewItem into hidden form fields, presumably to maintain state. If so, can this behavior be changed to disable state, or to store it in the session instead?
Thanks!
0
Carson
Top achievements
Rank 1
answered on 02 May 2011, 06:40 PM
Does anyone have a solution to the problem that Courtney has described?
If you try to use custom content in the Text field, and then POST your treeview, the potentially dangerous Request.Form
error occurs, just as she described.
EDIT
[ValidateInput(false)] attribute, on the controller action seems to work.
If you try to use custom content in the Text field, and then POST your treeview, the potentially dangerous Request.Form
error occurs, just as she described.
EDIT
[ValidateInput(false)] attribute, on the controller action seems to work.