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

[Solved] Sorting the checked nodes in treeview

3 Answers 252 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
pankaj
Top achievements
Rank 1
pankaj asked on 20 Oct 2008, 01:14 PM
Hi,

I am using RadTreeView control in radCombobox. I am using get_checkedNodes() method to get the checked nodes. This method is returning the collection of checked nodes but the order of the collection depends upon the values checked by user. I want this order in the order of index of the items in treeview. For example treeview is structured to have nodes A,B,C,D,E. If user checks in the order as D,B,C than collection returned is also in the order D,B,C. I want this collection in the order of index as B,C,D. Is there any way to sort this collection in javascript or to get the collection in the order of index. I am using 1 level depth of treeview control and I want this sorting in javascript.

Thanks,
Pankaj

3 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 22 Oct 2008, 03:55 PM
Hi pankaj,

Since get_checkedNodes returns an array of RadTreeNode objects, so you could sort this array by Node Text, e.g.

function getSortedCheckedNodes() { 
    var treeView = $find("<%= RadTreeView1.ClientID %>"); 
     
    var checkedNodes = treeView.get_checkedNodes(); 
     
    return checkedNodes.sort(sortNodes); 
 
function sortNodes(a, b) { 
    if (a.get_text() < b.get_text()) return -1; 
    if (a.get_text() > b.get_text()) return 1; 
    return 0; 

Best wishes,
Simon
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Usha Ganju
Top achievements
Rank 2
answered on 02 Nov 2009, 08:54 PM
I have RadTreeNode and I want to sor5t by Number after the tree is built.. Any suggestions.Here is my code:

RadTreeNode

 

node = new RadTreeNode(list[i].Number + " - " + list[i].Name, list[i].Id.ToString());

 

selectedNode.Nodes.Add(node);

0
Usha Ganju
Top achievements
Rank 2
answered on 02 Nov 2009, 08:55 PM
I have RadTreeNode and I want to sort by Number after the tree is built.. Any suggestions.Here is my code:

RadTreeNode

 

node = new RadTreeNode(list[i].Number + " - " + list[i].Name, list[i].Id.ToString());

 

selectedNode.Nodes.Add(node);

 

Tags
TreeView
Asked by
pankaj
Top achievements
Rank 1
Answers by
Simon
Telerik team
Usha Ganju
Top achievements
Rank 2
Share this question
or