treeTable plugin recursive expand and collapse issue

treeTable is a very simple jQuery plugin that renders tabular data in a tree format, but it(latest version 2.3 at the time of writing) has a few bugs one of it is its expand and collapse function are not recursive as they were claimed.

Here are two new collapse and expand functions which really are recursive, feel free to use.

// Recursively hide all node's children in a tree
// modified by http://cleancode.co.nz, current collapse is not recursive
  $.fn.Rcollapse = function() {
    $(this).removeClass("expanded").addClass("collapsed");

      childrenOf($(this)).each(function() {
        initialize($(this));

        if ($(this).is(".parent")) {
            $(this).Rcollapse();
        }

      
        this.style.display = "none"; // Performance! $(this).hide() is slow...
      });

      return this;
  };


  // Recursively show all node's children in a tree
  // modified by http://cleancode.co.nz, current expand is not recursive
  $.fn.Rexpand = function() {
      $(this).removeClass("collapsed").addClass("expanded");

      childrenOf($(this)).each(function() {
          initialize($(this));

          if ($(this).is(".parent")) {
              $(this).Rexpand();
          }

          // this.style.display = "table-row"; // Unfortunately this is not possible with IE 🙁
          $(this).show();
      });

      return this;
  };

Tags:

This entry was posted on Thursday, July 28th, 2011 at 2:40 am and is filed under Javascript. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “treeTable plugin recursive expand and collapse issue”

  1. Kailan says:

    You are so awsoeme for helping me solve this mystery.

Leave a Reply

*