TreeView

Description

The TreeView widget displays hierarchical data in a tree structure.

Official Kendo UI TreeView documentation

Examples

  • Basic Example
  • Passing additional options
  • Using global options

This example demonstrates initializing a TreeView widget with no additional options specified.

<ul data-bind="kendoTreeView: {}">
    <li>
        <span>Test 1</span>
        <ul>
            <li>Test 1A</li>
            <li>Test 1B</li>
        </ul>
    </li>
    <li>
        <span>Test2</span>
        <ul>
            <li>Test 2A</li>
            <li>Test 2B</li>
        </ul>
    </li>
</ul>
var ViewModel = function() {};

                            ko.applyBindings(new ViewModel());
  • Test 1
    • Test 1A
    • Test 1B
  • Test2
    • Test 2A
    • Test 2B

This example demonstrates passing additional options in the data-bind attribute. The kendoTreeItem binding can be applied to child elements to control the behavior of individual menu items.

<input type="checkbox" data-bind="checked: isTwoOpen" /> Open 2<br/>
<input type="checkbox" data-bind="checked: twoEnabled" /> Enable 2
<hr/>
<ul data-bind="kendoTreeView: {}">
    <li>
        <span>Test 1</span>
        <ul>
            <li>
                <span>Test 1A</span>
                <ul>
                    <li>Test 1Aa</li>
                    <li>Test 1Ab</li>
                </ul>
            </li>
            <li>Test 1B</li>
        </ul>
    </li>
    <li data-bind="kendoTreeItem: { expanded: isTwoOpen, enabled: twoEnabled, selected: isSelected }">
        <span>Test2</span>
        <ul>
            <li>Test 2A</li>
            <li>Test 2B</li>
        </ul>
    </li>
</ul>
var ViewModel = function() {
    this.twoEnabled = ko.observable(true);
    this.isTwoOpen = ko.observable(false);
    this.isSelected = ko.observable();
};

                            ko.applyBindings(new ViewModel());
Open 2
Enable 2
  • Test 1
    • Test 1A
      • Test 1Aa
      • Test 1Ab
    • Test 1B
  • Test2
    • Test 2A
    • Test 2B

This example demonstrates setting global options in ko.bindingHandlers.kendoTreeView.options. This helps to simplify the markup for settings that can be used as a default for all instances of this widget.

<ul data-bind="kendoTreeView: {}">
    <li>
        <span>Test 1</span>
        <ul>
            <li>
                <span>Test 1A</span>
                <ul>
                    <li>Test 1Aa</li>
                    <li>Test 1Ab</li>
                </ul>
            </li>
            <li>Test 1B</li>
        </ul>
    </li>
    <li>
        <span>Test2</span>
        <ul>
            <li>Test 2A</li>
            <li>Test 2B</li>
        </ul>
    </li>
</ul>
var ViewModel = function() {};

ko.bindingHandlers.kendoTreeView.options.animation = false;

                            ko.applyBindings(new ViewModel());
  • Test 1
    • Test 1A
      • Test 1Aa
      • Test 1Ab
    • Test 1B
  • Test2
    • Test 2A
    • Test 2B

Live Options

The kendoTreeView.md binding accepts all of the options that can be specified for the widget. However, when bound against an observable, these live options will update the widget or respond to updates from interactions with the widget.
expanded

Controls whether the tree item’s leaf is open

enabled

Determines if users can interact with the tree item

selected

Controls whether the tree item is selected

widget

If specified, will populate an observable with a reference to the actual widget

Future Plans

Better support for adding/inserting/removing nodes and responding to selections.