Home - Forums-.NET - FlyTreeView (ASP.NET) - Refresh a Node Client Side

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

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

Refresh a Node Client Side
Link Posted: 12-Mar-2007 05:52
Hello,

I am facing a problem refreshing a node client side.

As mentioned in another thread (http://www.9rays.net/forums/viewtopic.php?t=1102&highlight=refresh+node) refreshing a node involves iterating through all child nodes and remove each of them.

This works, but it does not work very well. I.e. if there are a lot of child nodes to remove the process can take a VERY long time (up to the point of Internet Explorer hanging itself).

Hence I tried a workaround:

function RefreshNode(item, argument)
        {
            // get the selected node
            var node = argument;
            
            // get its parent to retrieve the node's index
            var parent = node.getParent();            
            var index = node.i;
                        
            // create a new node and set its values (all this would not be necessary if there was a method to create a shallow copy)
            var newNode = new CFlyTreeNode();            
            newNode.setText(node.getText());
            newNode.setValue(node.getValue());
            newNode.setNavigateTarget(node.getNavigateTarget());
            newNode.setNavigateUrl(node.getNavigateUrl());
            newNode.setPopulateNodesOnDemand(true);  
            newNode.setContextMenuID(node.getContextMenuID());        
            
            // remove the old node and replace it with the new one
            node.remove();
            parent.insertNode(newNode, index);
            newNode.expand();


This works pretty well (a pity there is no copy() method to create a shallow copy of a node though).

The problem I am having is that I have no idea how to retrieve and set the URL of the image of a node.
Link Posted: 12-Mar-2007 09:37
You should probably pay attention to CFlyTreeNode.clone() client-side method.

Also, as you mentioned there's no setImageUrl client-side method so far.
Hope to get it complete (with some other useful features) within the next build.
Link Posted: 12-Mar-2007 11:05
[quote="EvgenyT"]You should probably pay attention to CFlyTreeNode.clone() client-side method.


Thanks for the answer Evgeny. However, I can be wrong here, but I was under the impression that the .clone() method created a deep copy of a node.

If that is the case using it to improve the performance when de-populating a node seems to be pretty pointless. I.e. I'd have to iterate through all child members of the cloned node to delete them. Leading me back to the initial problem.
Link Posted: 13-Mar-2007 00:00
I reread your first post.

The fact is that when you call node.remove(), it first removes all its child nodes (from DOM hierarchy).

So there's no performance difference in comparison when you just remove all child nodes one by one like in
http://www.9rays.net/forums/viewtopic.php?t=1102&highlight=refresh+node

Actually node.remove() does the same, but also removes itself.
Link Posted: 13-Mar-2007 21:11
[quote="EvgenyT"]I reread your first post.

The fact is that when you call node.remove(), it first removes all its child nodes (from DOM hierarchy).

So there's no performance difference in comparison when you just remove all child nodes one by one like in
http://www.9rays.net/forums/viewtopic.php?t=1102&highlight=refresh+node

Actually node.remove() does the same, but also removes itself.


Sorry for being such a pest ... yet, two things:

1.
While removing a nodes's every child by iterating takes a tremendously long time (up to the point of IE complaining that the script is slowing down all processes), removing the node itself takes no time at all.

I have no knowledge about the internals of the method .remove(), yet I'd kindly like to ask you to investigate the issue and maybe take a few minutes to test it.

Again, the workaround I described above works like a charm, apart from the newly created node not having an image.

2.
As you suggested I had a look at the clone() method. This method does - as the documentation implies - create a deep copy of a node. However, the image of the node itself goes missing (the images the of the cloned node's children are displayed properly).
Link Posted: 14-Mar-2007 02:28
Finally we moved some code from 4.2(beta) to 4.1(public release)

See CFlyTreeView.clearNodes() and CFlyTreeNode.clearChildNodes() client-side functions.

Probably this is what you need. It is available for download now.



Also regarding node.clone(). We do not have problems with it in our test case. Within a sample node we have

and node.clone() creates a copy that contains the same image.

Or do you set imageUrl in nodetype, or use absolute/relative url, whatever that is not cloned correctly?
Link Posted: 14-Mar-2007 04:22
Thanks for the CFlyTreeView.clearNodes() and CFlyTreeNode.clearChildNodes() client-side functions

[quote="EvgenyT"]
Also regarding node.clone(). We do not have problems with it in our test case. Within a sample node we have

and node.clone() creates a copy that contains the same image.

Or do you set imageUrl in nodetype, or use absolute/relative url, whatever that is not cloned correctly?


Those nodes are created server-side (via populateOnDemand) using the .ImageUrl Property, like so:

child.ImageUrl = "~/Images/Flytree/someImage.png";


Not really sure where I could be going wrong, maybe I am missing something in the client side part where I clone.
What I am trying to achieve is to filter the childnodes of a node by a search text. The following method is called through a contextMenuItem:

function Filter(item, nodeToSearch)
{
    // get the search text
    var searchText = prompt ("Filter by?","");

    // find all nodes that contain the searchText
    var foundNodes = nodeToSearch.findAll( function(node) { return  node.getText().toLowerCase().indexOf(searchText) != -1 } );

    // create a new node that will be inserted as
    // the first child node of the node whose content we filter
    var newNode = new CFlyTreeNode();            
    newNode.setText("Filtered: '" + searchText + "'");
    newNode.setPopulateNodesOnDemand(false);  

    // insert the new node
    node.insertNode(newNode, 0);

    // iterate through the search result,
    //create a clone of each item and add it to newly created node
    for( var i=0; i < foundNodes.length; i++)
    {
       var clonedNode = foundNodes[i].clone();
       newNode.addNode(clonedNode);
    }

    newNode.expand();
}