Kendo

  • UI Framework
  • Mobile
  • Demos
  • Roadmap
  • What's New
  • Download

Skin

  • Framework
  • UI Widgets
  • Integration

    • Description
    • View Code
    • Configuration (3)
    • Methods (11)
    • Events (7)

    The TreeView widget displays hierarchical data in a traditional tree structure, with support for interactive drag-and-drop reordering operations. A TreeView can be defined statically using HTML lists, or it can be dynamically bound to hierarchical data.

    Getting Started

    There are two primary ways to create a TreeView:

    1. Define a hierarchical list with static HTML
    2. Use dynamic data binding

    Static HTML definition is appropriate for small hierarchies and for data that does not change frequently. Data binding should be used for larger data sets and for data that changes frequently.

    Creating a treeview from HTML

    Create a hierarchical HTML list

    <ul id="treeview">
        <li>Item 1
            <ul>
                <li>Item 1.1</li>
                <li>Item 1.2</li>
            </ul>
        </li>
        <li>Item 2</li>
    </ul>

    Initialize the TreeView using a jQuery selector

    var treeview = $("#treeview").kendoTreeView();

    Creating a TreeView with data binding (local data source)

    Create a hierarchical HTML list

    <div id="treeview"></div>

    Initialize and bind the TreeView

    $("#treeview").kendoTreeView({
        dataSource: [
            { text: "Item 1", items: [
                { text: "Item 1.1" },
                { text: "Item 1.2" }
            ]},
            { text: "Item 2" }
        ]
    });

    Configuring TreeView behavior

    A number of TreeView behaviors can be easily controlled by simple configuration properties, such as animation behaviors and drag-and-drop behaviors. Refer to the demo Configuration tab for more API details.

    Enabling TreeView node drag-and-drop

    $("#treeview").kendoTreeView({
        dragAndDrop: true
    });

    When drag-and-drop is enabled, TreeView nodes can be dragged and dropped between all levels, with useful tooltips helping indicate where the node will be dropped.

    No code
    animation: Object
    A collection of {Animation} objects, used to change default animations. A value of false will disable all animations in the component.
    collapse: Animation
    The animation that will be used when collapsing items.
    expand: Animation
    The animation that will be used when expanding items.
    dataSource: Array
    The data that the TreeView will be bound to.
    dragAndDrop: Boolean(default: false)
    Controls whether the treeview nodes can be dragged and rearranged.
    • append (nodeData, parentNode)
      Appends a node to a treeview group.

      Example

      var treeview = $("#treeview").data("kendoTreeView");
      // appends a new node with the text "new node" to the node with id="firstItem"
      treeview.append({ text: "new node" }, document.getElementById("firstItem"));
      // moves the node with id="secondNode" as a last child of the node with id="firstItem"
      treeview.append(document.getElementById("secondNode"), document.getElementById("firstItem"));

      Parameters

      nodeData: NodeData
      JSON that specifies the node data, or a reference to a node in the TreeView.
      parentNode: Node (optional)
      The node that will contain the newly appended node. If not specified, the new node will be appended to the root group of the treeview.
    • collapse (nodes)
      Collapses nodes.

      Example

      var treeview = $("#treeview").data("kendoTreeView");
      // collapse the node with id="firstItem"
      treeview.collapse(document.getElementById("firstItem"));
      // collapse all nodes
      treeview.collapse(".k-item");

      Parameters

      nodes: Selector
      The nodes that are to be collapsed.
    • enable (nodes, enable)
      Enables or disables nodes.

      Example

      var treeview = $("#treeview").data("kendoTreeView");
      // disable the node with id="firstItem"
      treeview.enable(document.getElementById("firstItem"), false);
      // enable all nodes
      treeview.enable(".k-item");

      Parameters

      nodes: Selector
      The nodes that are to be enabled/disabled.
      enable: Boolean (optional, default: true)
      Whether the nodes should be enabled or disabled.
    • expand (nodes)
      Expands nodes.

      Example

      var treeview = $("#treeview").data("kendoTreeView");
      // expands the node with id="firstItem"
      treeview.expand(document.getElementById("firstItem"));
      // expands all nodes
      treeview.expand(".k-item");

      Parameters

      nodes: Selector
      The nodes that are to be expanded.
    • findByText (text) : Node
      Searches the treeview for a node that has specific text.

      Example

      var treeview = $("#treeview").data("kendoTreeView");
      // searches the treeview for the item that has the text "foo"
      var foundNode = treeview.findByText("foo");

      Parameters

      text: String
      The text that is being searched for.
      Returns
      Node The first node that contains the text.
    • insertAfter (nodeData, referenceNode)
      Inserts a node after another node.

      Example

      var treeview = $("#treeview").data("kendoTreeView");
      // inserts a new node with the text "new node" after the node with id="firstItem"
      treeview.insertAfter({ text: "new node" }, document.getElementById("firstItem"));
      // moves the node with id="secondNode" after the node with id="firstItem"
      treeview.insertAfter(document.getElementById("secondNode"), document.getElementById("firstItem"));

      Parameters

      nodeData: NodeData
      JSON that specifies the node data, or a reference to a node in the TreeView.
      referenceNode: Node
      The node that will be before the newly appended node.
    • insertBefore (nodeData, referenceNode)
      Inserts a node before another node.

      Example

      var treeview = $("#treeview").data("kendoTreeView");
      // inserts a new node with the text "new node" before the node with id="firstItem"
      treeview.insertBefore({ text: "new node" }, document.getElementById("firstItem"));
      // moves the node with id="secondNode" before the node with id="firstItem"
      treeview.insertBefore(document.getElementById("secondNode"), document.getElementById("firstItem"));

      Parameters

      nodeData: NodeData
      JSON that specifies the node data, or a reference to a node in the TreeView.
      referenceNode: Node
      The node that will be after the newly appended node.
    • remove (node)
      Removes a node

      Example

      var treeview = $("#treeview").data("kendoTreeView");
      // remove the node with id="firstItem"
      treeview.remove(document.getElementById("firstItem"));

      Parameters

      node: Selector
      The node that is to be removed.
    • select (node) : Node
      Gets/sets the selected node.

      Example

      var treeview = $("#treeview").data("kendoTreeView");
      // select the node with id="firstItem"
      treeview.select(document.getElementById("firstItem"));
      // get the currently selected node
      var selectedNode = treeview.select();

      Parameters

      node: Selector (optional)
      The node that should be selected.
      Returns
      Node The currently selected node
    • text (node) : String
      Get the text of a node.

      Example

      var treeview = $("#treeview").data("kendoTreeView");
      // get the text of the node with id="firstItem"
      var nodeText = treeview.text(document.getElementById("firstItem"));

      Parameters

      node: Selector
      The node that you need the text for.
      Returns
      String The text of the node.
    • toggle (node)
      Toggles a node between expanded and collapsed state.

      Example

      var treeview = $("#treeview").data("kendoTreeView");
      // toggle the node with id="firstItem"
      treeview.toggle(document.getElementById("firstItem"));

      Parameters

      node: jQueryObject
      The node that should be toggled.
    collapse
    Fires before a subgroup gets collapsed.

    Event data

    node : Node
    The collapsed node
    drag
    Fires while a node is being dragged.

    Event data

    sourceNode : Node
    The node that is being dragged.
    dropTarget : DomElement
    The element that the node is placed over.
    pageX : Integer
    The x coordinate of the mouse.
    pageY : Integer
    The y coordinate of the mouse.
    statusClass : String
    The status that the drag clue shows.
    setStatusClass : Function
    Allows a custom drag clue status to be set.
    dragend
    Fires after a node is has been dropped.

    Event data

    sourceNode : Node
    The node that is being dropped.
    destinationNode : Node
    The node that the sourceNode is being dropped upon.
    dropPosition : String
    Shows where the new sourceLocation would be.
    dragstart
    Fires before the dragging of a node starts.

    Event data

    sourceNode : Node
    The node that will be dragged.
    drop
    Fires when a node is being dropped.

    Event data

    sourceNode : Node
    The node that is being dropped.
    destinationNode : Node
    The node that the sourceNode is being dropped upon.
    valid : Boolean
    Whether this drop operation is permitted
    setValid : Function
    Allows the drop to be prevented.
    dropTarget : DomElement
    The element that the node is placed over.
    dropPosition : String
    Shows where the new sourceLocation would be.
    expand
    Fires before a subgroup gets expanded.

    Event data

    node : Node
    The expanded node
    select
    Fires when a node gets selected.

    Event data

    node : Node
    The selected node
    • Home
    • UI Framework
    • Mobile
    • Demos
    • Roadmap
    • What's New
    • Blogs
    • Forums
    • Documentation
    • FAQ
    • About
    • Follow us on Twitter
    • Subscribe to our RSS feed

    Kendo UI is powered by Telerik

    Copyright © 2011 Telerik Inc. All rights reserved.