This is a migrated thread and some comments may be shown as answers.

Expand/Collapse All JavaScript timeout

4 Answers 205 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
IT Help Desk
Top achievements
Rank 1
IT Help Desk asked on 01 Oct 2010, 06:12 PM
Hi,

I am running into the dreaded "A script is causing IE to run slowly" problem with expand and collapse all.  There are about 4000 items in the tree, but only about 50 or so are not leaf items.

Expand/Collapse all sample
http://www.telerik.com/help/aspnet-ajax/tree_clientexpandingcollapsing.html

I have tried both of these with no luck
http://www.telerik.com/help/aspnet-ajax/troubleshooting-treeview-script-causes-ie-run-slowly.html

Any other suggestions for getting this to not time out?  I have the same tree using Dyanmic Drive Simple Tree menu (http://www.dynamicdrive.com/dynamicindex1/navigate1.htm) and it is able to expand and collapse all just fine.

TIA

4 Answers, 1 is accepted

Sort by
0
Nikolay Tsenkov
Telerik team
answered on 04 Oct 2010, 01:21 PM
Hi Jason Nam,

You can timeOut the expand of the items with setTimeout (function (){ ... },0);
Please try that out for lets say timeOut of every 20 node expansions and let me know the results.

Hope this solves it!


Regards,
Nikolay Tsenkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
IT Help Desk
Top achievements
Rank 1
answered on 04 Oct 2010, 05:20 PM
Hi,

I have tried a few different ways with no luck.  Chrome and Firefox work without the modification.  IE still timing out every time.

I attached a data file to the support ticket, can you please try and reproduce on your side?  I am using  IE 8 on Windows 7 64bit.

Thanks

Here is the original:
function treeExpandAllNodes() {
    var treeView = $find("<%= rtvMain.ClientID %>");
    var nodes = treeView.get_allNodes();
 
    for (var i = 0; i < nodes.length; i++) {
        if (nodes[i].get_nodes() != null) {
            nodes[i].expand();
        }
    }
}

Here is try one:
function treeExpandAllNodes() {
    setTimeout(function () {
        var treeView = $find("<%= rtvMain.ClientID %>");
        var nodes = treeView.get_allNodes();
 
        for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].get_nodes() != null) {
                nodes[i].expand();
            }
        }
    }, 0);
}

Here is try two:
function treeExpandAllNodes() {
    var treeView = $find("<%= rtvMain.ClientID %>");
    var nodes = treeView.get_allNodes();
    var currentNode;
 
    for (var i = 0; i < nodes.length; i++) {
        if (nodes[i].get_nodes() != null) {
            currentNode = nodes[i];
            if (i % 20 == 0) {
                window.setTimeout(function() { currentNode.expand(); }, 0);
            }
            else {
                nodes[i].expand();
            }
        }
    }
}
0
IT Help Desk
Top achievements
Rank 1
answered on 05 Oct 2010, 11:26 PM
I figured this out on my own.  The majority of my nodes were leaf nodes, so no reason to be calling .expand() or .collapse() on those nodes.  Just adding this check fixed the issue.

function treeExpandAllNodes() {
    var treeView = $find("<%= rtvMain.ClientID %>");
    var nodes = treeView.get_allNodes();
 
    for (var i = 0; i < nodes.length; i++) {
        if (nodes[i].get_nodes() != null) {
            if (nodes[i].get_nodes().get_count() != 0) {
                nodes[i].expand();
            }
        }
    }
}
 
function treeCollapseAllNodes() {
    var treeView = $find("<%= rtvMain.ClientID %>");
    var nodes = treeView.get_allNodes();
 
    for (var i = 0; i < nodes.length; i++) {
        if (nodes[i].get_nodes() != null) {
            if (nodes[i].get_nodes().get_count() != 0) {
                nodes[i].collapse();
            }
        }
    }
}
0
Nikolay Tsenkov
Telerik team
answered on 06 Oct 2010, 08:12 AM
Hello Jason Nam,

Great that you solved the problem!
And thanks for posting it here!

Hope you will not experience any more hard time with our controls.


Regards,
Nikolay Tsenkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
TreeView
Asked by
IT Help Desk
Top achievements
Rank 1
Answers by
Nikolay Tsenkov
Telerik team
IT Help Desk
Top achievements
Rank 1
Share this question
or