ludo / jquery-treetable

jQuery plugin to show a tree structure in a table
http://ludo.cubicphuse.nl/jquery-treetable
GNU General Public License v2.0
741 stars 278 forks source link

Expand ALL for Large lists. #150

Open djlerman opened 10 years ago

djlerman commented 10 years ago

I have a large list ~2500. Which is common for my implementation.

I get the following error when doing an "Expand all". "A script on this page may be busy, or it may have stopped responding. You can stop the script now, or you can continue to see if the script will complete."

Is there a way to get this to work?

PriyankGahtori commented 9 years ago

I am also getting the same issue, in my project I have list ~5,000.

djlerman commented 9 years ago

I have not been able to find a solution so I added the following. If the number of rows in a table is over a certain amount then hide the caption that contains the "Expand All / Collapse All" triggers. Around 750 rows is the MAX for my usage.

        // hide caption if number of rows in table is over 750
        var rows = document.getElementById("treeTable").rows.length;

        if(rows >= 750) {
          $("#caption").hide();
        }
        else {
          $("#caption").show();
        }
johanndt commented 5 years ago

I know this is old, but we had the same issue... I made a change to at least do the expanding asynchronously and give the browser time to redraw the screen and not lock up. Here's my diff:

@@ -232,13 +232,25 @@
     };

     Node.prototype._showChildren = function() {
+      var chunk = 100;
       var child, _i, _len, _ref, _results;
       _ref = this.children;
+      _len = _ref.length;
       _results = [];
-      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
-        child = _ref[_i];
-        _results.push(child.show());
+      _i = 0;
+
+      function doChunk() {
+        var cnt = chunk;
+        while (cnt-- && _i < _len) {
+            child = _ref[_i];
+            _results.push(child.show());
+            _i++;
+        }
+        if (_i < _len) {
+            setTimeout(doChunk, 1);
+        }
       }
+      setTimeout(doChunk, 1);
       return _results;
     };

@@ -268,13 +280,25 @@
     };

     Tree.prototype.expandAll = function() {
+      var chunk = 25;
       var node, _i, _len, _ref, _results;
       _ref = this.nodes;
+      _len = _ref.length;
       _results = [];
-      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
-        node = _ref[_i];
-        _results.push(node.expand());
+      _i = 0;
+
+      function doChunk() {
+        var cnt = chunk;
+        while (cnt-- && _i < _len) {
+            node = _ref[_i];
+            _results.push(node.expand());
+            _i++;
+        }
+        if (_i < _len) {
+            setTimeout(doChunk, 1);
+        }
       }
+      setTimeout(doChunk, 1);
       return _results;
     };

Basically rewrote the loops to do chunks of rows and use setTimeout() as described here: https://stackoverflow.com/a/10344560/2172360