EasyUI Forum
November 04, 2025, 10:12:41 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: tree resort by target node [Solved]  (Read 7025 times)
devnull
Sr. Member
****
Posts: 431


View Profile
« on: January 03, 2015, 05:38:31 PM »

How can I resort ONLY the children of a particular tree node ?

I found this: http://www.jeasyui.com/forum/index.php?topic=2948.0 - but that reloads the entire tree which I don't want to do.

After adding a node to a tree, I want to resort it's siblings.


« Last Edit: January 04, 2015, 12:36:13 AM by devnull » Logged

-- Licensed User --
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: January 04, 2015, 12:17:32 AM »

The function below shows how to sort the tree nodes.
Code:
function sortNodes(tree, parentNode){
var t = $(tree);
var data = t.tree('getData', parentNode.target);
var nodes = $.extend(true, [], data.children||[]);
$.map(nodes, function(node){
t.tree('remove', node.target);
});
// sort the nodes
nodes.sort(function(n1,n2){
if (n1.text == n2.text){
return 0;
} else if (n1.text > n2.text){
return 1;
} else {
return -1;
}
});
// append the sorted nodes
t.tree('append', {
parent: parentNode.target,
data: nodes
});
}

Call the 'sortNodes' function to sort the children nodes of the selected node.
Code:
var t = $('#tt');	// the tree object
var selected = t.tree('getSelected');
if (selected){
sortNodes(t, selected)
}
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!