Hi, this is my treelist widget for Backbase:
You can download the treelist here. My website can be found at this address: http://www.grauw.nl/.
The treelist kind of looks like a regular table, but with some of the elements replaced by custom tags. Instead of a table
element, there is a g:treelist
, instead of a tr
element (inside the tbody
) there is a g:treelisttr
element, and instead of a td
element, there is g:treelisttd
. Now, if you only make those changes, the tree would work but there would be no nesting yet. The nesting is achieved by letting each treelist row point to its parent using the b:observe
attribute. It is probably most convenient to give every element an ID and refer to that, but you can also use relative paths.
A very simple example treelist would look like this:
<g:treelist> <thead> <tr> <th>Column</th> </tr> </thead> <tbody> <g:treelisttr id="tl-1"> <g:treelisttd>Row 1</g:treelisttd> </g:treelisttr> <g:treelisttr id="tl-1-1" b:observe="id('tl-1')"> <g:treelisttd>Row 2</g:treelisttd> </g:treelisttr> </tbody> </g:treelist>
Items can also be added to the tree dynamically. If they are added as children of another node, the other node will automatically become a folder, etcetera.
What you do have to take care of however is that the sub-item is placed in the correct location. The easiest way to do this is by using a b:destination that points to its parent, and a b:mode of ‘after’, as the link above does. Alternatively, you could also load the item ‘after’ another item that has the same parent, but that’ll be slightly less easy because you can’t do a convenient lookup by ID.
This can be caught in a behaviour as well, for example one like this:
<a g:parentnode="id('1126')"> <s:event b:on="command"> <s:render b:destination="xpath(@g:parentnode)" b:mode="after"> <g:treelisttr id="1127" b:observe="{@g:parentnode}"> <g:treelisttd>Sub-item</g:treelisttd> </g:treelisttr> </s:render> </s:event> </a>
With regard to speed, my treelist control is very fast in operation, but the initialisation can take some time if the set of data is too large. So I recommend people to implement an incrementally loading mechanism if they want to put larger amounts of data in this treelist.
Alternatively, one could also try to decrease the loading time by getting rid of the control’s construct event. This event mainly consists of determining the nesting (and indentation) of each row, and if you can let the server add that information instead, you should be able to get a significant speed-up.
~Grauw