Skip to main content


Optional. Specifies a template for Tree items

template?: (item: object, isFolder: boolean) => string | null;


The template function takes two parameters:

  • item - an object of a Tree item
  • isFolder - defines whether an item is a folder

and returns either a string or null.

Tip. The callback function together with the isFolder parameter allows you to specify a template for child items only.


const tree = new dhx.Tree("tree_container", {
template: ({ value }, isFolder) => {
const template = `
<div className="dhx_tree_template">
<span className="dhx_tree_template__value">${value}</span>
<div className="dhx_tree_template__rows">
<button className="dhx_tree_template__button remove">
<i className="far fa-trash-alt dhx_tree_template__icon dhx_tree_template__icon--danger"></i>
return isFolder ? null : template;

Related sample: Tree. Handling events in template

Change log:

added in v7.2