This is a migrated thread and some comments may be shown as answers.

[Solved] TreeView node with image

3 Answers 119 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
RES
Top achievements
Rank 1
RES asked on 13 Apr 2012, 11:31 PM
I have a TreeView with a properties pane for editing related properties of the currently selected node.  I'm doing an AJAX POST to update the properties of the selected node including the description which is the text of the selected node.  When my OnSuccess callback function is called I update the node's text with the new description.  The problem is when I update the text like the following it wipes out the image.

$(node).find("> div > .t-in").text(data.Description);

So to get around this I first copy the outer HTML of the image, append the new description and reinsert the HTML to the span element.  Unless I'm missing something to make this simpler why isn't there a separate element for the text to make it easier to update?

I also noticed that the image's HTML doesn't have a closing tag as well as the hidden input that holds the node's value.

3 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 16 Apr 2012, 09:24 AM
Hello Travis,

Instead of extracting and inserting the image, you can directly replace the text node value like this:

$(node).find("> div > .t-in")[0].lastChild.nodeValue = data.Description;

Indeed, the API for that is missing and we will consider adding it in the future.

> I also noticed that the image's HTML doesn't have a closing tag as well as the hidden input that holds the node's value. 

Both of these tags are empty (i.e. have no closing tag, like <br />).

Greetings,
Alex Gyoshev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
RES
Top achievements
Rank 1
answered on 16 Apr 2012, 06:03 PM
Regarding updating node text, thanks for a cleaner solution.

On the closing tags thing this is an example of what I'm getting in my markup.
<div class="t-top t-bot">
    <span class="t-icon t-minus"></span>
    <span class="t-in">
        <img class="t-image" alt="image" src="/content/images/icons/clientmap.png">Template 1
    </span>
    <input class="t-input" name="itemValue" value="00000000-0000-0000-0000-000000000000" type="hidden">
</div>

Shouldn't the image and hidden input tags be closed with /> instead of just > ?  Definitely not a deal breaker but I thought I should point it out.
0
Alex Gyoshev
Telerik team
answered on 17 Apr 2012, 10:11 AM
Hello Travis,

The images in the treeview online demos render the tags as empty, and looking at the code, it seems that this hasn't changed for a while. Either way, rendering the empty tag endings should be an issue for you only if you strive for XHTML validation, and does not have any side effects in HTML pages.

All the best,
Alex Gyoshev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
Tags
TreeView
Asked by
RES
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
RES
Top achievements
Rank 1
Share this question
or