Skip to main content

TreeCollection overview

A set of API methods and events that allow you to work with data of a component with tree-like structure. Applicable to Menu, Ribbon, Sidebar, Toolbar, Tree, TreeGrid.

Methods

NameDescription
add()adds an item to a component
canCopy()checks whether it is possible to copy a control into some other control
copy()adds a copy of an item and places it in the specified position
eachChild()iterates through child items of a control
eachParent()iterates through all the parent items (the immediate parent and its parent, etc until the parent is the component itself)
exists()checks whether the specified item exists in the component
filter()filters controls by some criteria
forEach()iterates over all items of a tree collection
getFilters()returns an object with the applied filters
getId()gets the ID of an item
getIndex()gets the current position of an item
getItem()gets an item by its ID
getItems()gets the child items of a control
getLength()counts child items of a control
getParent()gets the ID of the parent of the control
getRoot()returns the ID of the master component
haveItems()checks whether an item has children
isSaved()checks whether the changes made in a tree collection are saved
load()loads items from a file
loadItems()loads child items of a control from a file
move()moves items to different positions
parse()loads a collection of items from a local source
refreshItems()refreshes child items of a control
remove()removes an item
removeAll()clears the component of all controls
resetFilter()resets the active filters
restoreOrder()restores the component to the state previous to sorting / filtering
save()saves changes made in a tree collection to the server side
serialize()serializes the component data into JSON, XML or CSV format
sort()sorts controls according to some criteria
update()changes an item

Events

NameDescription
afterAddfires after adding a new item into a tree collection
afterItemLoadfires after loading an item
afterRemovefires after removing a new item from a tree collection
beforeAddfires before adding a new item into a tree collection
beforeItemLoadfires before loading an item
beforeRemovefires before removing an item from a tree collection
changefires when a tree collection is modified
filterfires after filtering a tree collection
loadfires when items are loaded in a tree collection
loadErrorfires when loading of data fails
removeAllfires when all items are removed from a tree collection
Ways of applying events

To call the event of TreeCollection, you may use either of the two syntaxes:

  • common syntax (via the data object of the component)
menu.data.events.on("afterAdd", function(newItem){
console.log("A new item is added");
});
  • or short syntax (right through the component)
menu.events.on("afterAdd", function(newItem){
console.log("A new item is added");
});