JAVASCRIPT
Elements in a tree structure
All samples are using Ink.requireModules
, please read how to use it at Ink.requireModules section
Shows elements in a tree structure which can be expanded and contracted.
A TreeView is built with "node"s and "children". "node"s are li
tags, and "children" are ul
tags.
You can build your TreeView out of a regular UL and LI element structure which you already use to display lists with several levels.
If you want a node to be open when the TreeView is built, just add the data-open="true" attribute to it.
Method name | Description |
---|---|
new TreeView(selector, [options]) | Constructor |
.close(node) | Closes one of the tree nodes |
.isOpen(node) | Checks if a node is open. |
.isParent(node) | Checks if a node is a parent. |
.open(node) | Opens one of the tree nodes |
.toggle(node) | Toggles a node state |
selector
Element or selector.options
Options object, containing:options.node
Selector for the nodes. Defaults to 'li'.options.children
Selector for the children. Defaults to 'ul'.options.parentClass
CSS classes to be added to parent nodes. Defaults to 'parent'.options.openClass
CSS classes to be added to the icon when a parent is open. Defaults to 'fa fa-minus-circle'.options.closedClass
CSS classes to be added to the icon when a parent is closed. Defaults to 'fa fa-plus-circle'.options.hideClass
CSS Class to toggle visibility of the children. Defaults to 'hide-all'.options.iconTag
The name of icon tag. The component tries to find a tag with that name as a direct child of the node. If it doesn't find it, it creates it. Defaults to 'i'.options.stopDefault
Flag to stops the default behavior of the click handler. Defaults to true.Example
Demo
Code
Usage with data-attributes
Demo
Code
Closes one of the tree nodes
Make sure you pass the node's Element
node
The node you wish to close.Checks if a node is open.
node
The tree node to checkChecks if a node is a parent.
node
Node to checkOpens one of the tree nodes
Make sure you pass the node's Element
node
The node you wish to open.Toggles a node state
node
The node to toggle.