- Basic Skins
- Global Templates
- Inline Templates
- Template Helper Directives
- Supported Template Scope Variables
Custom node templates are most likely overkill for style tweaks. Making the look and feel of your tree match the rest of your application can often be accomplished with a bit of css and your own twisties. IVH Treeview ships with only minimal styling and you are encouraged to apply your own styles.
Using the default template your tree will have the following general layout to aid in styling:
ul.ivh-treeview
li.ivh-treeview-node[?.ivh-treeview-node-collapsed][?.ivh-treeview-node-leaf]
<!-- begin node template -->
.ivh-treeview-node-content
.ivh-treeview-twistie-wrapper
.ivh-treeview-twistie
[?.ivh-treeview-twistie-collapsed]
[?.ivh-treeview-twistie-expanded]
[?.ivh-treeview-twistie-leaf]
.ivh-treeview-checkbox-wrapper
.ivh-treeview-checkbox
.ivh-treeview-node-label
ul.ivh-treeview
[... more nodes]
[... more nodes]
Where ivh-treeview-node-collapsed
and the various twistie classnames are
conditionally applied as appropriate.
The top level li
for a given node is give the classname
ivh-treeview-node-leaf
when it is a leaf node.
Tree node templates can be set globally using the nodeTpl
options:
app.config(function(ivhTreeviewOptionsProvider) {
ivhTreeviewOptionsProvider.set({
nodeTpl: '<custom-template></custom-template>'
});
});
Want different node templates for different trees? This can be accomplished using inline templates. Inline templates can be specified in any of three ways:
With the ivh-treeview-node-tpl
attribute:
<div ivh-treeview="fancy.bag"
ivh-treeview-node-tpl="variableWithTplAsString"></div>
Demo: Custom templates: inline
As a property in the ivh-treeview-options
object:
<div ivh-treeview="fancy.bag"
ivh-treeview-options="{nodeTpl: variableWithTplAsString}"></div>
Or as transcluded content in the treeview directive itself:
<div ivh-treeview="fancy.bag">
<script type="text/ng-template">
<div title="{{trvw.label(node)}}">
<span ivh-treeview-toggle>
<span ivh-treeview-twistie></span>
</span>
<span ng-if="trvw.useCheckboxes()" ivh-treeview-checkbox>
</span>
<span class="ivh-treeview-node-label" ivh-treeview-toggle>
{{trvw.label(node)}}
</span>
<div ivh-treeview-children></div>
</div>
</script>
</div>
Demo: Custom templates: transcluded
Note the use of the ng-template script tag wrapping the rest of the transcluded content, this wrapper is a mandatory. Also note that this form is intended to serve as a convenient and declarative way to essentially provide a template string to your treeview. The template itself does not (currently) have access a transcluded scope.
You have access to a number of helper directives when building your node templates. These are mostly optional but should make your life a bit easier, not that all support both element and attribute level usage:
ivh-treeview-toggle
(attribute) Clicking this element will expand or collapse the tree node if it is not a leaf.ivh-treeview-twistie
(attribute) Display as either an "expanded" or "collapsed" twistie as appropriate.ivh-treeview-checkbox
(attribute|element) A checkbox that is "plugged in" to the treeview. It will reflect your node's selected state and update parents and children appropriately out of the box.ivh-treeview-children
(attribute|element) The recursive step. If you want your tree to display more than one level of nodes you will need to place this some where, or have your own way of getting child nodes into the view.
node
A reference to the tree node itself. Note that in general you should use controller helper methods to access node properties when possible.
depth
The depth of the current node in the tree. The root node will be at depth 0
,
its children will be at depth 1
, etc.
trvw
A reference to the treeview controller with a number of useful properties and helper functions:
trvw.select(Object node[, Boolean isSelected])
Set the seleted state ofnode
toisSelected
. The will update parent and child node selected states appropriately.isSelected
defaults totrue
.trvw.isSelected(Object node) -> Boolean
Returnstrue
ifnode
is selected andfalse
otherwise.trvw.toggleSelected(Object node)
Toggles the selected state ofnode
. This will update parent and child note selected states appropriately.trvw.expand(Object node[, Boolean isExpanded])
Set the expanded state ofnode
toisExpanded
, i.e. expand or collapsenode
.isExpanded
defaults totrue
.trvw.isExpanded(Object node) --> Boolean
Returnstrue
ifnode
is expanded andfalse
otherwise.trvw.toggleExpanded(Object node)
Toggle the expanded state ofnode
.trvw.isLeaf(Object node) --> Boolean
Returnstrue
ifnode
is a leaf node in the tree andfalse
otherwise.trvw.label(Object node) --> String
Returns the label attribute ofnode
as determined by thelabelAttribute
treeview option.trvw.root() --> Array|Object
Returns the tree root as handed toivh-treeview
.trvw.children(Object node) --> Array
Returns the array of children fornode
. Returns an empty array ifnode
has no children or thechildrenAttribute
property value is not defined.trvw.opts() --> Object
Returns a merged version of the global and local options.trvw.isVisible(Object node) --> Boolean
Returnstrue
ifnode
should be considered visible under the current filter andfalse
otherwise. Note that this only relates to treeview filters and does not take into account whether or notnode
can actually be seen as a result of expanded/collapsed parents.trvw.useCheckboxes() --> Boolean
Returnstrue
if checkboxes should be used in the template andfalse
otherwise.