All of the examples on this page, are built on the predefined JSON example from the data sources demo.

Selecting nodes

The user can select nodes by clicking on them (in this example if Ctrl is held multiple nodes can be selected).

You can define a node to be selected onload by using the selected config setting (check documentation for more).

The get_* functions are most useful for keyboard shortcuts - they can move either the hover or selected states - this is defined using the ui.hover_mode config setting or using the force argument in each of the functions.

The hover_branch functions moves the hover state to a specific node.

There are a few ways to select nodes programatically:

  // Data settings omitted
  selected : "pjson_1",
  rules : { multiple : "ctrl" }
// Button codes

Open/close nodes

The user can open and close nodes by clicking the open/close icon where applicable. Here are the programmtic ways:

// Button codes

Creating nodes

You can create nodes programatically with the create function. You can place the new node inside another node (even at a specific position among its children) or "below" or "after" the node (if you omit the reference node, the currently selected is used). This is controlled by the rules.createat config option, and the third argument of the create function.

// Button codes
$.tree_reference('demo0').create({ data: 'Created node' },$('#pjson0_3'));
$.tree_reference('demo0').create({ attributes : { 'class' : 'cc' }, data: { title : 'ID and ICON', icon : '../media/images/ok.png' } },$('#pjson0_3'));

Delete nodes (refresh tree)

The remove function removes the currently selected node, or the node it receives as an argument from the tree.

The refresh function is also present in this example so that you can refresh the tree after deleting nodes.

By default deleting nodes is not allowed, this is why in this example rules.deletable is set to "all" (check the documentation for more)

$(function () {
      // Data settings omitted
      rules : {
        deletable : "all"
// Button codes

Rename nodes

The rename function renames the currently selected node, or the node it receives as an argument.

NOTE: when passing an argument (renaming a node that is not selected), renaming might look a little odd according to theme.

// Button codes

Moving/copying nodes

The user can move nodes around using drag'n'drop. As for copying the rules.drag_copy config option controls the behavior (disabled, when the ctrl key is down, always copy).

In this example the rules.draggable config option is set to "all" so you can drag all nodes around.

You can drag nodes between trees which have rules.multitree set to true.

You can also use the copy, cut, paste functions on the first tree.

$(function () {
      // Data settings omitted
      rules : {
        multitree : true,
        draggable : "all"
// Button codes