dhtmlxTree sorting question

I have a sizeable tree (600+ nodes) that I am loading and setting “tree.enableSmartXMLParsing(1);” and I have an onClick node event to sort child nodes of the opened node however I would like to know how I can sort only those nodes that have children then in the same branch sort the leafs ?

Parent Node

[+] elephant

[+] lion

[+] tiger

[+] zebra

|-- bear

|-- giraffe

So the branch nodes get sorted separatly from the leafs ?

Make sense ? Hope you can help ?



You can use custom sorting function


var childA=tree.hasChildren(idA);
var childB=tree.hasChildren(idB);
//separate items with child and childless
if (childA && !childB) return 1;
if (!childA && childB) return -1;

//sorting inside groups
return (tree.getItemText(idA)>tree.getItemText(idB)?1:-1);


Hi there !
Perfect solution and great responsiveness ! Congratulations on a great product and keep up the good work !

Only thing I’ve done is switch states on returns

if (childA && !childB) return 1;
if (!childA && childB) return -1;

if (!childA && childB) return 1;
if (childA && !childB) return -1;

This put the folders first in the ordering and orders both branches and leafs…