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

RadDropDownTree Setting Alternate Selected Text

3 Answers 125 Views
DropDownTree
This is a migrated thread and some comments may be shown as answers.
Marc Vanderveen
Top achievements
Rank 1
Marc Vanderveen asked on 09 Jan 2017, 06:54 PM

Hello,

I have a usercontrol with a single select DropDownTree where I need to display slightly different text than what is show as the node text.  This text is basically a more user readable form of the full path.  Currently I am storing that alternate text as node attributes attached server side:

    Dim newNodeL3 As New RadTreeNode(tr_row.BodyPartL3Text, tr_Body.BodyPartID)

newNodeL3.Attributes("FullText") =  row_Body.BodyPartFullText

3 Answers, 1 is accepted

Sort by
0
Marc Vanderveen
Top achievements
Rank 1
answered on 09 Jan 2017, 06:56 PM
Sorry, this was posted prematurely - creating the rest of the question now
0
Marc Vanderveen
Top achievements
Rank 1
answered on 09 Jan 2017, 07:09 PM

continuing...

I have no problem accessing and updating to the alternate text using a RadTreeView1_DropDownClosed client event, and I am doing so by updating the inner  HTML:

        
    var initialInnerHTML = sender.get_element().innerHTML;
    var adjustedInnerHTML = initialInnerHTML.replace(currentText, selectedFullTextString);
    sender.get_element().innerHTML = adjustedInnerHTML;

 

but this is not working for me when the node is pre-selected server side because of course this event does not fire on page load.

I've tried adding similar code to an OnClientLoad event and it shows the new value, but it seems to disable the drop down tree:

selectedFullTextString = '<span class=\"rddtFakeInput\">' + treeView.get_selectedNode().get_attributes().getAttribute("FullText") + '</span>';
var currentText = '<span class=\"rddtFakeInput\">' + sender._selectedText + '</span>';
var initialInnerHTML = sender.get_element().innerHTML;
var adjustedInnerHTML = initialInnerHTML.replace(currentText, selectedFullTextString);
sender.get_element().innerHTML = adjustedInnerHTML;

 

Here is a Data element to help conceptualize the issue:

Tree Node L1 (Text:Arm) 

      Tree Node L2 (Text:Left)

           Tree Node L3 (Text:Hand)

Full Path text would be Arm --> Left --> Hand and the selected Item text would be just 'Hand'.

I am trying to show the custom value "Left Hand" that is stored as an attribute on the L3 Node. Any suggestions? 

Thanks!

Marc Vanderveen

 

 

 

 

0
Ivan Danchev
Telerik team
answered on 12 Jan 2017, 12:39 PM
Hello Marc,

If you want to change the text of a node that is pre-selected on the server you can do so in the DropDownTree's OnClientLoad event handler as demonstrated in the code snippet below, using the RadDropDownTree, the embedded RadTreeView and the RadTreeNode client side objects' methods:
<script type="text/javascript">
    function OnClientLoad(sender) {
        var tree = sender.get_embeddedTree();
        var selectedNode = tree.get_selectedNode();
        if (selectedNode) {
            var parent = selectedNode.get_parent();
            //the following check ensures the selected node is not a Root node
            if (parent != tree) {
                var oldText = selectedNode.get_text();
                var newText = parent.get_text() + "-->" + oldText;
                selectedNode.set_text(newText);
            }
        };
    }
</script>


Regards,
Ivan Danchev
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
DropDownTree
Asked by
Marc Vanderveen
Top achievements
Rank 1
Answers by
Marc Vanderveen
Top achievements
Rank 1
Ivan Danchev
Telerik team
Share this question
or