Skip to main content

data

Optional. Sets a dataset for a tree

info

Please note that if you specify the id fields in the tree collection, their values should be unique. You can also omit the id fields in the tree collection. In this case they will be generated automatically.

data?: object[];

Parameters:

Each data object can have the following properties:

value(string) the value of an item
id(string | number) the id of an item
opened(boolean) optional, defines whether an item is opened by default
checkbox(boolean) optional, enables/disables displaying a checkbox for a tree item
items(array) an array of children items
icon(object) allows adding custom icons for a tree item
Related sample: Tree. Custom dataset icons

Example

const 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"
}
}
]
}
];

const tree = new dhx.Tree("tree", {
data: dataset
});

Related samples:

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

tree.data.update("Books", {checkbox:false});