data

sets a dataset for a tree

array data;

Example

var data = new dhx.TreeCollection();
data.load("../common/treedata.json");
var tree = new dhx.Tree("tree", {data: data});

Related samples

Details

Each data object can have the following properties:

  • id - (string) the id of a tree item, auto-generated if not set
  • value - (string) the value of a tree item
  • items - (array) optional, an array of children items
  • opened - (boolean) optional, defines whether an item is opened by default
  • checkbox - (boolean) optional, enables/disables displaying a checkbox for a tree item
  • icon - (object) allows adding custom icons for a tree item
    Related sample:  Custom dataset icons - DHTMLX Tree
var tree = new dhx.Tree("tree", {
    data:[
        {
            "value": "Books",
            "id": "Books",
            "opened": true,
            "checkbox": true,
            "items": [
                {
                    "value": "Thrillers",
                    "id": "Thrillers",
                    "icon": { 
                        "folder": "fas fa-book", 
                        "openFolder": "fas fa-book-open", 
                        "file": "fas fa-file"
                    }
                }
            ]
        }
    ]
});

You can disable displaying a checkbox for a tree item via the update method of tree collection.

tree.data.update("Books", {checkbox:false});
  • parent - (string) the id of the parent of a tree item

For example, you can get the parent of an item using the getItem method of tree collection.

tree.data.getItem("Thrillers").parent
// "Books"
 
tree.data.getItem("Books").parent
// "_ROOT_u1574768464563"
See also
Back to top