The function below shows how to sort the tree nodes.
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.
var t = $('#tt'); // the tree object
var selected = t.tree('getSelected');
if (selected){
sortNodes(t, selected)
}