How to add and expand all / collapse everything in jQuery TreeTable in Apache Wicket app?

I use the jQuery TreeTable plugin in the same way mentioned in the jQuery Tree Table blog entry for Wicket .

Now I want to bind some JavaScript code in the expand all / collapse all button.

The following code does not work.

$(".treeTable").treeTable().expand(); 

And

 $(".treeTable").treeTable(); $(".treeTable").expand(); 
+4
source share
2 answers

Very nice task.

I created the function "expand all" (because it does not have it). Here you have:

 $.fn.expandAll = function() { $(this).find("tr").removeClass("collapsed").addClass("expanded").each(function(){ $(this).expand(); }); }; 

To use it, simply do:

 $(".treeTable").expandAll(); 

Hope this helps.

+10
source

Here is the answer for those who are still looking for this:

You need to somehow trigger these events, for example: let's say that you put two href tags, here is the compatible code:

To expand all nodes:

 $('#expandAllTasks').on('click', function(e) { e.preventDefault(); $('.gantt_treetable').treetable('expandAll'); }); 

To collapse all nodes:

 $('#collapseAllTasks').on('click', function(e) { e.preventDefault(); $('.gantt_treetable').treetable('collapseAll'); }); 

Hope this helps someone :)

0
source

All Articles