ludo / jquery-plugins Goto Github PK
View Code? Open in Web Editor NEWjQuery treeTable has moved, please update your bookmarks!
Home Page: http://ludo.cubicphuse.nl/jquery-plugins/treeTable/doc/
jQuery treeTable has moved, please update your bookmarks!
Home Page: http://ludo.cubicphuse.nl/jquery-plugins/treeTable/doc/
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.
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));
}
}
};
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>
It would be nice to have an option to configure the width of each column.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.