Skip to main content

Configuration

Checkboxes for items​

Tree with three-state checkboxes showing checked and intermediate states in DHTMLX Suite

DHTMLX Tree supports two-state and three-state checkboxes. A two-state checkbox lets users check and uncheck a tree item. A three-state checkbox also has an intermediate state that appears when only some children of a parent item are checked.

Set the checkbox configuration option to true to enable checkboxes for items:

const tree = new dhx.Tree("tree_container", { checkbox: true });

Related sample: Tree. Inline editing, drag-and-drop and checkboxes

Collapsed mode​

To initialize a tree in the collapsed state, use the collapsed property:

const tree = new dhx.Tree("tree_container", {
collapsed: true,
});

Related sample: Tree. Collapsed mode

Editing of items​

Tree item being edited inline with an active text editor in DHTMLX Suite

Set the editable configuration property to true to let users edit the text of Tree items:

const tree = new dhx.Tree("tree_container", { editable: true });

Related sample: Tree. Inline editing, drag-and-drop and checkboxes

Key navigation​

Set the keyNavigation property to true to enable key navigation in a tree:

const tree = new dhx.Tree("tree_container", { keyNavigation: true });

After you select an item, use the arrow keys to navigate the tree:

Up arrow keymoves the selection to the item above
Down arrow keymoves the selection to the item below
Right arrow keyopens the selected folder
Left arrow keycloses the selected open folder

Related sample: Tree. Key navigation

Selection of items​

Tree with a highlighted selected item among folders and files in DHTMLX Suite

Related sample: Tree. Disable selection

The default Tree configuration lets users select and highlight an item. To disable selection, set the selection configuration property to false:

const tree = new dhx.Tree("tree_container", {
selection: false,
});

Tooltips for items​

Use the tooltip configuration option to add tooltips to Tree items. You can enable the default tooltips, pass a template function that renders custom content in the tooltips, or pass an object with extended tooltip options. Check the following examples:

  • A configuration object with a custom template and a display delay:
const tree = new dhx.Tree("tree_container", {
tooltip: {
htmlEnable: true,
// the 500ms delay before showing
showDelay: 500,
// the tooltip will appear to the right of the item
position: "right",
// a CSS class for styling
css: "custom-tooltip-style",
// the template function
template: (item, event) => {
// display the item's name and the number of children (if any)
const count = item.items ? ` (${item.items.length})` : "";
return `<span className="tooltip-title">${item.value}</span><span className="tooltip-count">${count}</span>`;
}
}
});
  • A function that defines the tooltip content:
const tree = new dhx.Tree("tree_container", {
tooltip: (item) =>
(item.value + (item.items ? ` (${item.items?.length})` : "") + "")
});

Related sample: Tree. Tooltip template

The tooltip property can have the following types of values:

  • boolean — if true, enables the standard tooltip that shows the value property of the item
  • function — a template function that returns the string content of the tooltip
  • object — a configuration object for detailed customization of tooltip behavior and appearance. The object can contain the following properties:
    • template - (optional) a function that determines the content of the tooltip. It takes two arguments:
      • item - (object) the data object of a tree item.
      • event - (object) the native mouse event (MouseEvent). The template function must return a string.
    • force - (optional) if true, forces the tooltip to appear without delays. In this case, the tooltip ignores the showDelay and hideDelay settings. The default value is false.
    • showDelay - (optional) the delay before the tooltip appears (in milliseconds).
    • hideDelay - (optional) the delay before the tooltip hides (in milliseconds).
    • htmlEnable - (optional) specifies whether the tooltip can contain HTML markup.
    • margin - (optional) the margin between the tree item and the tooltip (in pixels). The default value is 8.
    • position - (optional) the position of the tooltip relative to the item. The possible values are: "right", "bottom", "center", "left", "top". The default value is "bottom".
    • css - (optional) the name of the CSS class for customizing the style of the tooltip container.