Home - Forums-.NET - FlyTreeView (ASP.NET) - [SOLVED] Refresh a node through a ContextMenu entry

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

[SOLVED] Refresh a node through a ContextMenu entry
Link Posted: 11-Feb-2007 22:22
Greetings,

I am trying to let the user refresh a Node that is populated on demand by having him click a corresponding context-menu entry.

The markup:

            
                
                
            
            
                
                    
                
            


Clicking the 'Refresh' entry in the context-menu will call the following client-side function:

        function RefreshNode(item, argument)
        {
            var node = argument;
            var childNodes = node.getChildNodes();
            for(var i = 0; i < childNodes.length; i++)
            {
                var curChild = childNodes[i];
                curChild.remove();
            }
            node.setPopulateNodesOnDemand(true);
        }


This actually works pretty well apart from one thing: after the user clicked the 'Refresh' entry in the ContextMenu the Node will depopulate. Yet, despite setting populating on demand to true, the node will then lose it's [+] sign. Clicking once where the sign is supposed to be will make it appear. After that it works properly again.

Am I missing something?
Link Posted: 11-Feb-2007 22:34
Actually the reason is that setPopulateNodesOnDemand does not forces node to update its appearance (show [+] sign).

There can be a possible workaround for this behavior.

Try to change your code to

        function RefreshNode(item, argument)
        {
            var node = argument;
            node.setPopulateNodesOnDemand(true);
            var childNodes = node.getChildNodes();
            for(var i = 0; i < childNodes.length; i++)
            {
                var curChild = childNodes[i];
                curChild.remove();
            }
            
        }
Link Posted: 12-Feb-2007 02:26
Thanks for the quick answer Ivgeny ... may I mention here that support for FlyTreeView is far beyond what I am used to from other companies ... it's fast, friendly, competent ... nothing short of excellent

Anyway,

your workaround works like a charm. I expanded the the function a little bit to react properly depending on whether the node was expanded before the refresh or not. In case people need to do something similiar here is the code:

function RefreshNode(item, argument)
        {
            var node = argument;    
            var expanded = node.getExpanded();  
              
            node.setPopulateNodesOnDemand(true);
            node.collapse();
            
            var childNodes = node.getChildNodes();
            for(var i = 0; i < childNodes.length; i++)
            {
                var curChild = childNodes[i];
                curChild.remove();
            }
            if( expanded )
            {                
                node.expand();
            }
        }