views:

372

answers:

2

I am using Ludo van den Boom's treeTable jquery plugin to represent a table as a expandable tree. Once my data set becomes large both Firefox and IE timeout on executing the call to the plugin in my $(document).ready.

The plugin's public method is:

$.fn.treeTable = function(opts) {
    options = $.extend({}, $.fn.treeTable.defaults, opts);

    return this.each(function() {
        $(this).addClass("treeTable").find("tbody tr").each(function() {
            // Initialize root nodes only whenever possible
            if (!options.expandable || $(this)[0].className.search("child-of-") == -1) {
                initialize($(this));
            }
        });
    });
};

It gets called from:

$(document).ready(function() {
   $(".reportTable").treeTable();
});

Where reportTable is the class of a fairly large table. initialize is a recursive call.

Can this be modified to to avoid the timeouts both browsers give? I've seen a reference to using setTimeout ( See question #779379) but I am not sure how to apply that.

A: 

any function called from setTimeout or setInterval runs outside the main loop and therefore won't block other scripts. It's as simple as:

window.onload = function(){setTimeout("your_function()",0)}
SpliFF
Works. Thanks.
Mark Fox
Could you post some details on how you got this to work pretty please?
BenB
With v1.4 of the plugin?
BenB
define "details"... it's simply really. You call a function via setTimeout instead of just calling the function. The browser wont stop when it sees the setTimeout statements so the onReady/onload function will complete promptly and the time-consuming function will run without blocking the page or event scripts. If the page scripts aren't blocked the browser is more tolerant of long-running scripts.
SpliFF
A: 

How large is the data set that you are using? how many nodes are in the tree? And how many root nodes does it have?

You might want to check out version 2.2.2 of the treeTable plugin, which should initialize large trees a lot faster. This version can be downloaded at the plugin's project page.