Parent tree nodes can be easily added to the tree from script with the help of insertNewNext() method. The following incoming parameters should be indicated in this method:
<script> tree.insertNewNext(1,2,"New Node 2",0,0,0,0,"CHILD,CHECKED"); </script>
Method insertNewChild() allows to add a new child item for the chosen tree node. The parameters the user should indicate are:
<script> tree.insertNewChild(0,1,"New Node 1",0,0,0,0,"SELECT,CALL,TOP,CHILD,CHECKED"); </script>
The item added as a child will be created always the last among other child items for the specified parent.
Any item can be easily removed from the tree in the following way:
<script>t tree.deleteItem(itemId, selectParent); </script>
The parameters the user should specify are:
The following method allows the user to remove all child items of a certain node very easily:
<script> tree.deleteChildItems(itemId); </script>
There is a possibility in dhtmlxTree to set whether a parent item will be expanded or not when a child item is added to it.
<script> tree.openOnItemAdded(mode); </script>
The method can be set either to true (the parent item will be expanded on child adding) or to false (the parent item won't be expanded).
There is the possibility to expand/collapse any node in dhtmlxTree from script. The only value that the user should indicate, is the id of the item in question:
<script> tree.openItem(itemId); // expand the indicated item tree.closeItem(itemId); // collapse the indicated item </script>
The user can also expand/collapse all items in the tree. The optional parameter here is the id of the item starting from which all items will be expanded/collapsed:
<script> tree.openAllItems(itemId); // expand all items tree.closeAllItems(itemId); // collapse all items </script>
The method to expand all tree items that is similar to the above mentioned one but that works in dynamical trees:
<script> tree.openAllItemsDynamic(itemId); // expands all items in a dynamical tree </script>
The method to expand a list of tree items in dynamical tree (items are expanded one by one, the next item will be opened only when the previous one is loaded):
<script> tree.openItemsDynamic(list,flag); </script>
The parameters are:
There is a method that can prevent the item from collapsing:
<script> tree.setItemCloseable(itemId,flag); </script>
The parameters here are as follows:
Item's state (expanded|collapsed) can be got in the following way:
<script> var state = tree.getOpenState(itemId); </script>
The method returns true if the item in question is expanded, and false if the item is collapsed.
By locking the tree, the user denies expanding|collapsing tree nodes. By default the tree isn't locked (false). To lock the tree, lockTree() method should be set to true:
<script> tree.lockTree(true); // false to unlock the tree </script>
Any item, whether it is a parent or a child one, can be also locked by method lockItem():
<script> tree.lockItem(itemId); // id of the item as the input parameter </script>
To get the state (locked|unlocked) of any item in the tree, the user should apply the following method:
<script> var itemState = tree.isLocked(itemId); // returns current item's state </script>
If the item in question is locked, the method returns true, if it is unlocked, false is returned.
Any item in the tree can be made editable - double click on the item allows to edit its title text. By default all items in the tree are not editable (false). To make them so, the user should write the following code line:
<script> tree.enableItemEditor(true); // false to deny items editing </script>
The user can activate the editor for a specified item from script with the help of method editItem(). The only parameter that should be specified is id of this item:
<script> tree.editItem(itemId); </script>
Item's editor can be easily deactivated from script bringing the item back to its normal view:
<script> tree.stopEdit(); </script>
The event that starts item's editing can be defined from script in the following way:
<script> tree.setEditStartAction(click, dblclick); </script>
The parameters define the following:
The user has the possibility to store states of items to cookies in the following way:
<script> tree.saveOpenStates(cookie_name,cookie_param); </script>
The parameters of this method are:
There is a method that restores items' states (expanded|collapsed) from cookie's information:
<script> tree.loadOpenStates(cookie_name); // the parameter is optional </script>
Item's selection can be also stored in cookies in the following way:
<script> tree.saveSelectedItem(cookie_name,cookie_param); </script>
The parameters of this method are:
Item's selection can be restored from cookie in the following way:
<script> tree.restoreSelectedItem(cookie_name); // the parameter is optional </script>
Method saveState() stores the whole tree to cookies:
<script> tree.saveState(cookie_name,cookie_param); </script>
The parameters of this method are:
Method loadState() restores the whole tree from cookies:
<script> tree.loadState(cookie_name); // the parameter is optional </script>
dhtmlxTree allows its users to save the selected node automatically in cookies. Method enableAutoSavingSelected() is used to switch this on|off in the tree:
<script> tree.enableAutoSavingSelected(mode,cookieName); </script>
The parameters are:
The user can set the label (text) of a tree node in the following way:
<script> tree.setItemText(itemId, newLabel, newTooltip); </script>
The parameters are as follows:
The user has the possibility to get text of item's label indicating item's id in the following way:
<script> var text = tree.getItemText(itemId); </script>
The user can also get the text of the currently selected item in the following way:
<script> var textSelected = tree.getSelectedItemText(); </script>
The following line of code is responsible for node's color (text color) in the tree:
<script> tree.setItemColor(itemId, defaultColor, selectedColor); </script>
The parameters the user should specify are as follows:
Item's color can be easily got by item id in the following way:
<script> car color = tree.getItemColor(itemId); </script>
The object returned by the above mentioned method has parameters { acolor:“value”, scolor:“value” } where:
The format of the color will be the same as it was set in setItemColor() method.
There are three ways to set tooltip for an item in dhtmlxTree:
<script> tree.enableAutoTooltips(true|false); // false by default </script>
Item's tooltip is also easy to get with the help of getItemTooltip() method indicating item id:
<script> var tooltip = tree.getItemTooltip(itemId); <script>
The following method is used to refresh data for the specified node:
<script> tree.refreshItem(itemId); // if item id is not indicated, id of the top tree item will be used </script>
The code string mentioned above presupposes that all the child items of the indicated node are removed, an XML file (indicated in setXMLAutoLoading(); auto loading should be activated) is loaded from the server. The data from this file is used for creating new child items of the node in question.
The following method is used to refresh data for several nodes:
<script> tree.refreshItems(itemIdList, source); </script>
The parameters of this method include the list of items that should be refreshed, and the path to the XML file from which new data will be loaded. In this case, the data is refreshed only for nodes indicated in itemIdList (not their children).
There is one more possibility to refresh tree data. smartRefreshBranch() method is able to load XML from the server and refresh data for the specified branch (text, icons, items). It should be noted that the current position and all changes introduced by the user stay the same in this case.
<script> tree.smartRefreshBranch(itemId,source); </script>
The parameters here are responsible for:
Method smartRefreshItem() is responsible for loading XML which data is used for refreshing the specified item in the tree. As with the previous method, this one keeps the current position of the item and all other changes introduced by the user.
<script> tree.smartRefreshItem(itemId,source); </script>
The parameters are as follows:
There is a simple way of updating items in dhmlxTree - updateItem() method. The used should indicate the id of the item that is going to be updated, and parameters that are going to be updated:
<script> tree.updateItem(itemId,name,im0,im1,im2,achecked); </script>
The parameters of this method are as follows:
The following methods allow the user to get ids of all parent tree nodes:
<script> var parents = tree.getAllItemsWithKids(); // returns the array of nodes ids </script>
The user can get the list of ids of all tree items that do not have child nodes (childless items):
<script> var childless = tree.getAllChildless(); // returns the array of nodes ids </script>
The user can easily get ids of all sub-items starting from the item which id is indicated in this method:
<script> var subItems = tree.getAllSubItems(itemId); </script>
Getting the list of all sub-items ids for the specified item is quite easy. This parent item id should be specified:
<script> tree.getSubItems(itemId); </script>
The user can change any node's id if there's such a need in the following way:
<script> tree.changeItemId(itemCurrentId,itemNewId); </script>
The user can get any child item id by its index (sequence number) and the id of its parent:
<script> var childId = tree.getItemIdByIndex(itemId,index); </script>
The parameters are:
Child item's index (sequence number) can be easily got by its id:
<script> var childIndex = tree.getIndexById(itemId); </script>
The parameter is id of the child item which index the user wants to get.
getParentId() method can be used to get item's parent id:
<script> var parent = tree.getParentId(itemId); </script>
The id of the item should be indicated as the parameter.
The ids of all checked/unchecked items in the tree can be easily got by getAllChecked() method:
<script> var list = tree.getAllChecked(); // returns the array of all checked items ids // or var list = tree.getAllUnchecked(); // returns the array of all unchecked items ids </script>
The method, similar to the above mentioned ones, exists for getting the ids of all partially checked items in the tree:
<script> var list = tree.getAllPartiallyChecked(); // returns the array of all checked items ids </script>
Ids of all checked branches in the tree can be got like this:
<script> var list = tree.getAllCheckedBranches(); // returns the array of all checked branches ids </script>
Selected item's id is easy to get through getSelectedItemId() method which takes item id as the parameter:
<script> var selectId = tree.getSelectedItemId(); </script>
There is a simple way of setting list separator in dhtmlxTree:
<script> tree.setListDelimeter(separator); // by default the separator is "," </script>
There is only one parameter here - separator - char or string used for separating items in lists.
Any item in the tree can be moved with the help of moveItem() method.
<script> tree.moveItem(itemId, mode, targetId, targetTree); </script>
The following parameters should be specified for this method:
One more way of nodes moving is through doCut() and doPaste() commands. But they work only with selected items:
<script> tree.doCut(); // marks the selected item as cut tree.doPaste(itemId); // id of a new parent node </script>
The cut item will be made a child node of the item indicated in the method doPaste().
To clear the mark made by doCut() method, the user is advised to use clearCut() one:
<script> tree.clearCut(); </script>
There is a method in dhtmlxTree that allows the user to get item's current level (position in hierarchy) indicating this item's id:
<script> var level = getLevel(itemId); </script>
There is the possibility to set top offset for a tree item using the following method:
<script> tree.setItemTopOffset(itemId,value); </script>
The parameters are:
The user can set calculation mode for the tree in the following way:
<script> tree.setChildCalcMode(mode); // disabled by default </script>
There are the following mode variants available:
All tree child nodes will be calculated in this mode.
Along with setting the calculation mode for child items, the user can specify calculation HTML like this:
<script> tree.setChildCalcHTML(htmlA,htmlB); </script>
The parameters here are:
The number of child items of a certain parent can be got in the following way:
<script> var childItems = tree.hasChildren(itemId); </script>
User data can be set for any tree item in dhtmlxTree:
<script> tree.setUserData(itemId,name,value); </script>
The parameters of this method are:
User data set for a tree node can be got in the following way:
<script> var userData = tree.getUserData(itemId,name); </script>
The parameters of this method are:
Any node if the tree can have link-like functionality specified for it. The link for an item can be set by user in XML. The user should also specify onClick event for the item with link-like functionality.