Giter VIP home page Giter VIP logo

jquery-plugins's People

Contributors

ludo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

sadanand

jquery-plugins's Issues

Cannot remove indentation by setting indent to 0

I have a simple two level tree table in which I do not want the second level to be indented. I tried to remove the indentation by setting the indent configuration to 0:

        $("#order_table").treeTable( {indent: 0} );

However, this seems to hide the expand/collapse icon and the tree cannot be expanded any more. Is there another way to do this?

Thanks.

Fixed length for variable string

treeTable allows user defined child prefixes but uses the fixed length of 9 from the default:

   function parentOf(node) {
     var classNames = node[0].className.split(' ');
-    
+
     for(key in classNames) {
       if(classNames[key].match(options.childPrefix)) {
-        return $("#" + classNames[key].substring(9));
+        return $("#" + classNames[key].substring(options.childPrefix.length));
       }
     }
   };

Patch for lazy node creation

I need to create additional elements on the fly. So I patched treeTable a bit. Not very elegant since I am quite new to jquery ;-)

+
+  fillRow = function(tr, klass, name, content)
+  {
+    var span = document.createElement('span');
+    span.className = klass;
+    span.innerHTML = name;
+
+    var td = document.createElement('td');
+    td.appendChild(span);
+    tr.appendChild(td);
+
+    td = document.createElement('td');
+    td.innerHTML = content;
+    tr.appendChild(td);
+
+    return tr;
+  }
+
+ 
+  $.fn.treeTable.createLazyParent = function(id, klass, name, content, parentid)
+  {
+    var tr = document.createElement('tr');
+    tr.id = id;
+    if (parentid)
+      tr.className = "lazyfill parent node child-of-" + parentid;
+    else    
+      tr.className = "lazyfill parent node";

+    return fillRow(tr, klass, name, content);
+  }
+
+  $.fn.treeTable.createChild = function(id, klass, name, content, parentid, oddrow)
+  {
+    tr = document.createElement('tr');
+    tr.id = id;
+    if(parentid)
+      parentid = "child-of-" + parentid;
+
+    if(oddrow)
+      tr.className = "odd " + parentid;
+    else
+      tr.className = "even " + parentid;
+
+    return fillRow(tr, klass, name, content);
+  }
+
   $.fn.treeTable.defaults = {
     childPrefix: "child-of-",
     clickableNodeNames: false,
     expandable: true,
     indent: 19,
     initialState: "collapsed",
-    treeColumn: 0
+    treeColumn: 0,
+    lazyfiller:null
   };
-  
+
   // Recursively hide all node's children in a tree
   $.fn.collapse = function() {
     $(this).addClass("collapsed");
-    
+
     childrenOf($(this)).each(function() {
       if(!$(this).hasClass("collapsed")) {
         $(this).collapse();
       }
-      
+
       this.style.display = "none"; // Performance! $(this).hide() is slow...
     });
-    
+
     return this;
   };
-  
+
   // Recursively show all node's children in a tree
   $.fn.expand = function() {
     $(this).removeClass("collapsed").addClass("expanded");
-    
+
+    if (options.lazyfiller && $(this).hasClass("lazyfill"))
+    {
+      $(this).removeClass("lazyfill");
+      options.lazyfiller(this)
+    }
+
     childrenOf($(this)).each(function() {
       initialize($(this));
-      
+
       if($(this).is(".expanded.parent")) {
         $(this).expand();
       }

Usage is like this when adapting index.html from the sources:

    var nodectr = 1;

    lazyfillerdemo = function(parent)
    {
       tr1 = $.fn.treeTable.createLazyParent ("lazynode-" + nodectr, "folder", "node-" + nodectr, "asdfasdf n" + nodectr);
       tr2 = $.fn.treeTable.createChild("lazychild-a-" + nodectr, "folder", "child-a-" + nodectr, "asdfasdf ca" + nodectr, null, false);
       tr3 = $.fn.treeTable.createChild("lazychild-b-" + nodectr, "folder", "child-b-" + nodectr, "asdfasdf cb" + nodectr, null, true);

       nodectr++;

       $(tr3).appendBranchTo(parent[0]);
       $(tr2).appendBranchTo(parent[0]);
       $(tr1).appendBranchTo(parent[0]);
    }

    $(".example").treeTable({ lazyfiller: lazyfillerdemo});
<table class="example">
  <caption>Simple treeTable Example</caption>
  <thead>
    <tr>
      <th>TreeColumn</th>
      <th>Additional data</th>
    </tr>
  </thead>
  <tbody>
    <tr id="ex0-node-1">
      <td>Node 1: Click on the icon in front of me to expand this branch.</td>
      <td>I live in the second column.</td>
    </tr>
    <tr id="lazy-1" class="lazyfill parent">
      <td>lazy click.</td>
      <td>I live in the second column.</td>
    </tr>
    <tr id="ex0-node-1-1" class="child-of-ex0-node-1">
      <td>Node 1.1: Look, I am a table row <em>and</em> I am part of a tree!</td>
      <td>Interesting.</td>
    </tr>
    <tr id="ex0-node-1-1-1" class="child-of-ex0-node-1-1">
      <td>Node 1.1.1: I am part of the tree too!</td>
      <td>That's it!</td>
    </tr>
  </tbody>
</table>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.