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

Attributes - non unique values

3 Answers 75 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Darren
Top achievements
Rank 1
Darren asked on 02 Sep 2008, 05:28 PM
Do the values in a custom attribute need to be unique?

I am wanting to create a custom attribute called Group to link a bunch of nodes together (they do not have the same parent) and then be able to find them all using findNodeByAttribute - but according to the documentation it looks like this method only returns 1 node. If this is the case is there another way to do this?

Thanks.

3 Answers, 1 is accepted

Sort by
0
Darren
Top achievements
Rank 1
answered on 02 Sep 2008, 10:20 PM
I have the following code and for some reason I can't get the findNodeByAttribute to work - it doesn't return a node. I know the attribute key and value are being set properly but it doesn't work. I am using this on a contentpage hooked up to a master page if that makes any difference. Thanks.

Protected Sub rtvMain_NodeDataBound(ByVal sender As Object, ByVal e As RadTreeNodeEventArgs) Handles rtvMain.NodeDataBound
 e.Node.Attributes.Add("Class", (TryCast(e.Node.DataItem, DataRowView))("ClassID").ToString())
End Sub

function UncheckClassEntries()
{  
    var tree = $find("<%= rtvMain.ClientID %>");
    var node = tree.findNodeByAttribute("Class","306");
    node.highlight();
}
0
Accepted
Veselin Vasilev
Telerik team
answered on 03 Sep 2008, 12:15 PM
Hi Darren,

You are right that the findNodeByAttribute method returns the first node that match.
If you want to find all nodes that have that attribute you need to iterate through all nodes of the tree and check if they have this attribute:

var tree = $find("<%= rtvMain.ClientID %>"); 
var nodes = tree.get_allNodes(); 
 
for (var i = 0; i < nodes.length; i++) 
   var node = nodes[i]; 
   if (node.get_attributes().getAttribute("ClassID") == "306"
   { 
       alert(node.get_text()); 
   } 

I suggest that you change the name of the attribute from "class" (which is a standard HTML attribute) to something else like ClassID and try again.

All the best,
Veskoni
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Darren
Top achievements
Rank 1
answered on 03 Sep 2008, 09:24 PM
Thank you.
Tags
TreeView
Asked by
Darren
Top achievements
Rank 1
Answers by
Darren
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or