Auto expand child when parent checked on treelist using javascript

206 views Asked by At

Can someone teach me how to expand child item on tree list when parent item was checked in JavaScript?

Current,i had function on JavaScript to check/unchecked parent item and child item. But this function fail to auto expand the child item when parent item was checked. Can someone lead me a hand please?

Here is my JavaScript.

  var parenItemSelected = false;
        function OnClientNodeClicked(sender, args) {
            var currNode = args.get_item();
            var childNodes = currNode.get_childItems();
            var nodeCount = currNode.get_childItems().length;
            var parentItem = currNode.get_parentItem();

            if (parentItem) {

                parenItemSelected = true;
                parentItem.set_selected(true);
            }

            if (currNode.get_selected()) {
                CheckAllChildren(childNodes, nodeCount);
            }
            else {
                UnCheckAllChildren(currNode, childNodes, nodeCount);
            }
            parenItemSelected = false;
        }

        function UnCheckAllChildren(currNode, nodes, nodecount) {
            var i;
            for (i = 0; i < nodecount; i++) {
                nodes[i].set_selected(false);
            }
            currNode.set_selected(false);
        }

        function CheckAllChildren(nodes, nodecount) {
            var i;

            if (!parenItemSelected) {
                for (i = 0; i < nodecount; i++) {
                    nodes[i].set_selected(true);
                }
            }
        }

Code from C# or vb.net are welcome.

Thanks.

0

There are 0 answers