Hi all,
I''m struggling a bit with displaying a subtree with all the child nodes
of a
node. A node in this case is an Agent model extending ActiveRecord::Base and
using acts_as_nested_set :scope => :product_id.
I would like to generate the below HTML code that displays a tree. The ASCII
connectors can easily be replaced by icons.
<table border=0 cellspacing=0 cellpadding=0>
<tr><td nowrap><b>node 1</b></td></tr>
<tr><td>
<table border=0 cellspacing=0 cellpadding=0>
<tr>
<table border=0 cellspacing=0 cellpadding=0>
<tr><td nowrap>|-</td><td nowrap>node
1.1</td></tr></table>
</tr>
<tr>
<table border=0 cellspacing=0 cellpadding=0>
<tr><td nowrap>|-</td><td nowrap>node
1.2</td></tr></table>
</tr>
<tr><td>
<table border=0 cellspacing=0 cellpadding=0>
<tr>
<table border=0 cellspacing=0 cellpadding=0>
<tr><td nowrap>| </td><td
nowrap>|-</td><td nowrap>node
1.2.1</td></tr></table>
</tr>
<tr>
<table border=0 cellspacing=0 cellpadding=0>
<tr><td nowrap>| </td><td
nowrap>\-</td><td nowrap>node
1.2.2</td></tr></table>
</tr>
</table>
</td></tr>
<tr>
<table border=0 cellspacing=0 cellpadding=0>
<tr><td nowrap>\-</td><td nowrap>node
1.3</td></tr></table>
</tr>
</table>
</td></tr>
<tr><td nowrap>node 2</td></tr>
</table>
I have this method defined in the AgentsHelper module:
def show_agents_tree(current_agent, child_agents)
html = "<table class=\"agent-tree\">\n"
html += "<tr><td
nowrap>#{agent_link(current_agent)}</td></tr>\n"
if !agents.empty?
html += "<tr><td>\n"
html += show_agents_tree(agents.shift, child_agents)
html += "</td></tr>\n"
end
html += "</table>\n"
end
It generates HTML code that just displays each agent as a child of the
previous agent. Can anyone help me to get the right level (O, 1, 2, ...)
dependent indentation working? Any help is appreciated.
Thanks,
Mark
Jean-Christophe Michel
2007-May-28 21:50 UTC
[Betternestedset-talk] Trouble with tree view
Hi, Le 24 mai 07 ? 23:12, Noten Mark a ?crit :> I''m struggling a bit with displaying a subtree with all the child > nodes of a > node. A node in this case is an Agent model extending > ActiveRecord::Base and > using acts_as_nested_set :scope => :product_id.I just posted on http://opensource.symetrie.com/trac/better_nested_set/wiki/RecursiveMenu an example of a helper I use to display a dynamic menu with selected path developped (only the hierarchies in the selected path are open). Hope it will help with your question. Jean-Christophe Michel -- symetrie.com Better Nested Set for rails: http://opensource.symetrie.com/trac/better_nested_set