Check documentation for the latest version of dhtmlxSuite Initializing TreeView DHTMLX Docs

Initializing TreeView

TreeView's source files

To begin working with a TreeView component you need to include treeview js/css files on the page. There are two of them:

    <link rel="stylesheet" type="text/css" href="codebase/dhtmlxtreeview.css">
    <script src="codebase/dhtmlxtreeview.js"></script>

In case you're working with the whole DHTMLX Suite, there's no need to include extra files - dhtmlx js/css files will be enough:

    <link rel="stylesheet" type="text/css" href="codebase/dhtmlx.css">
    <script src="codebase/dhtmlx.js"></script>

Including source files from CDN

To include JS/CSS files of "dhtmlxSuite" package from CDN, you should set direct links to dhtmlx.js and dhtmlx.css files:

<link rel="stylesheet" href="" 
<script src="" 

By setting links in this way you will get the latest version of dhtmlxSuite. To get some particular version, just specify the number of the required version in the link, like this:

<link rel="stylesheet" href="" 
<script src="" 


var myTreeView = new dhtmlXTreeView({
    parent:         "treeviewObj",  // id/object, container for treeview
    skin:           "dhx_terrace",  // string, optional, treeview's skin
    iconset:        "font_awesome", // string, optional, sets the font-awesome icons
    multiselect:    true,           // boolean, optional, enables multiselect
    checkboxes:     true,           // boolean, optional, enables checkboxes
    dnd:            true,           // boolean, optional, enables drag-and-drop
    context_menu:   true,           // boolean, optional, enables context menu
    json:           "filename.json",// string, optional, json file with struct
    xml:            "filename.xml", // string, optional, xml file with struct
    items:          [],             // array, optional, array with tree struct
    onload:         function(){}    // callable, optional, callback for load

The order of loading (if several initial params specified at a time) is: json, xml, items.

Minimal initialization

To initialize TreeView in an HTML element, you need to complete two steps:

1) define a parent container, where treeview will be placed:

    <div id="treeviewObj">
        <!-- treeview body will be here later -->

2) create a TreeView object and place it into the HTML object that you've just created:

var myTreeView = new dhtmlXTreeView({
    items: [
        {id: 1, text: "Books", open: 1, items: [
            {id: 2, text: "Turned at Dark / C. C. Hunter"},
            {id: 3, text: "Daire Meets Ever / Alyson Noël"},
            {id: 4, text: "Socs and Greasers / Rob Lowe"},
            {id: 5, text: "Privacy and Terms.pdf"},
            {id: 6, text: "Licence Agreement.pdf"}

Related sample:  Object API init

Attaching to a cell

Pay attention that if you attach treeview to a cell, the "parent" attribute should be omitted.

1) Attaching to the layout's cell

    // treeview config here

Related sample:  Integration with layout

2) Attaching to the tabbar's tab

    // treeview config here

Related sample:  Integration with tabbar

3) Attaching to the accordion's cell

    // treeview config here

Related sample:  Integration with accordion

4) Attaching to the window

    // treeview config here

Related sample:  Integration with window

5) Attaching to the carousel's cell

    // treeview config here

Related sample:  Integration with carousel

6) Attaching to the popup

    // treeview config here

Related sample:  Integration with popup

7) Attaching to the sidebar's cell

    // treeview config here

Related sample:  Integration with sidebar

Back to top