1
votes

I callled root.appendChild() to add couple children to a treepanel root and called root.expand() to expand the tree but the child nodes did not show until I click on any of the the sort button on the header. Is there any property I need to set to show the child node programmally?

Thanks for help.

The following is the code:

        tree.getRootNode().removeAll();

        var root = tree.setRootNode({
            PRTNUM:'root',
            id: 'treeRoot',
            leaf: false
        });

        for (var i = 0; i < result.data.length; i++) {
            var rec = result.data[i];
            var node = root.appendChild({
                PRTNUM: rec.PRTNUM,
                DESC: rec.DESC,   
                icon: this.convertTypeToIcon(rec.TYPE),
                id: rec.PRTNUM,
                leaf: true

            });
        }


        root.expand();
2
is root visible in your config?dbrin
Yes the root shows correctly. Thanks.CHI TANG
do you start with an empty root? Meaning no other children?dbrin
Yes. removeAll() child node before appendChild() loop. Thanks a lot.CHI TANG

2 Answers

2
votes

Since your root node originally had no children it was marked as a leaf. I found that the following works for parent nodes that are initially leaves and you have to add nodes programatically:

parentNode.set("leaf", false);  //must be set to work properly
parentNode.appendChild(newChild);
parentNode.expand();
1
votes

I found out that adding the following lines after calling appendChild() fix thie 'tree grid did not expand until click on 'sort' column button. Thanks.

        root.expandChildren(true);

        root.sort(function() {});