Tree Class
To create interactive trees (useful for folders or hierarchies).
Options are:
+ allow_multiselection: allow to select multiple elements using the shift key
+ allow_rename: double click to rename items in the tree
+ allow_drag: drag elements around
+ height
Item data should be in the next format:
{
id: unique_identifier,
content: what to show in the HTML (if omited id will be shown)
children: [] array with another object with the same structure
className: class
precontent: HTML inserted before the content
visible: boolean, to hide it
dataset: dataset for the element
onDragData: callback in case the user drags this item somewhere else
}
To catch events use tree.root.addEventListener(...)
item_selected : receive { item: node, data: node.data }
item_dblclicked
item_renamed
item_moved
Constructor
Tree
()
Item Index
Methods
- addItemToSelection
- clear
- collapseItem
- expandItem
- filterByName
- filterByName
- getAncestors
- getAncestors
- getChildren
- getItem
- getParent
- getSelectedItem
- getSelectedItems
- insertItem
- isInsideArea
- isItemSelected
- moveItem
- removeItem
- removeItemFromSelection
- scrollToItem
- setSelectedItem
- updateItem
- updateItemId
- updateTree
Methods
addItemToSelection
-
id
adds item to selection (multiple selection)
Parameters:
-
id
String
clear
-
keep_root
clears all the items
Parameters:
-
keep_root
Boolif you want to keep the root item
collapseItem
-
id
in case an item is expanded, it collapses it to hide children
Parameters:
-
id
String
expandItem
-
id
in case an item is collapsed, it expands it to show children
Parameters:
-
id
String
filterByName
-
name
remove from the tree the items that do not have a name that matches the string
Parameters:
-
name
String
filterByName
-
name
remove from the tree the items that do not have a name that matches the string
Parameters:
-
name
String
getAncestors
-
id
returns an array with all the ancestors
Parameters:
-
id
String
Returns:
getAncestors
-
id
returns an array with all the ancestors
Parameters:
-
id
String
Returns:
getChildren
-
id
-
[only_direct=false]
returns the children of an item
Parameters:
-
id
Stringcould be string or node directly
-
[only_direct=false]
Bool optionalto get only direct children
Returns:
getItem
-
id
get the item with that id, returns the HTML element
Parameters:
-
id
String
Returns:
getParent
-
id
returns the parent of a item
Parameters:
-
id
String
Returns:
getSelectedItem
()
HTML
returns the first selected item (its HTML element)
Returns:
getSelectedItems
()
HTML
returns an array with the selected items (its HTML elements)
Returns:
insertItem
-
data
-
parent_id
-
position
-
options
update tree with new data (old data will be thrown away)
Parameters:
-
data
Object -
parent_id
String -
position
Numberindex in case you want to add it before the last position
-
options
Object
Returns:
isInsideArea
-
id
Tells you if the item its out of the view due to the scrolling
Parameters:
-
id
String
isItemSelected
-
id
returns if an item is selected
Parameters:
-
id
String
Returns:
moveItem
-
id
-
parent_id
move item with id to be child of parent_id
Parameters:
-
id
String -
parent_id
String
Returns:
removeItem
-
id
remove item with given id
Parameters:
-
id
String
Returns:
removeItemFromSelection
-
id
remove item from selection (multiple selection)
Parameters:
-
id
String
scrollToItem
-
id
Scrolls to center this item
Parameters:
-
id
String
setSelectedItem
-
id
mark item as selected
Parameters:
-
id
String
updateItem
-
id
-
data
update a given item with new data
Parameters:
-
id
String -
data
Object
updateItemId
-
old_id
-
new_id
update a given item id and the link with its children
Parameters:
-
old_id
String -
new_id
String
updateTree
-
data
update tree with new data (old data will be thrown away)
Parameters:
-
data
Object