Upgrading to 3.0: Opening Node on Anchor Click vs Expand Icon

395 views
Skip to first unread message

Gregg Bolinger

unread,
Mar 8, 2014, 1:16:01 AM3/8/14
to jst...@googlegroups.com
I'm upgrading to 3.0 from 1.0 and I have the following code defined for the types plugin:

{
  "default": {
    "select_node": function (e) {
      var NODE = this._get_node(e);
      log(NODE);
      type = $(NODE).attr("type");
      if (type == NodeType.leafDomain || type == NodeType.leafGenerator) {
        if (!this.is_open(e)) {
          this.toggle_node(e);
        }
      } else {
        this.toggle_node(e);
      }
      return true;
    }
  }

This allowed the opening/closing of a node if I clicked on the text.  In 3.0 this doesn't work because "default" is only applied to nodes that don't have a type and all my nodes have a type.  In 3.0, how can I open/close a node by clicking on the anchor rather than the <i class="jstree-icon jstree-ocl"></i> element?

Thanks


Ivan Bozhanov

unread,
Mar 8, 2014, 2:19:53 AM3/8/14
to jst...@googlegroups.com
Use the event, something like:

$('#tree')
  .on('select_node.jstree', function (e, data) { data.instance.open_node(data.node); })
  .jstree({ ... })

Travas Nolte

unread,
Apr 16, 2014, 12:56:58 PM4/16/14
to jst...@googlegroups.com
Hi Ivan,

This thread points me in the right direction, but in our implementation we use the tree to organize data. For example, we have "Products", then underneath that we have the "Categories", then underneath that we have the individual items that can be used dragged to another tree. We make "Products" and "Categories" non selectable and disabled so that the user cannot select them. The issue I'm having is that the select_node event doesn't appear to fire when clicking on disabled nodes. Is that correct or am I overlooking something?  If it is correct, do you have a recommended approach?

Many Thanks!

Travas

Ivan Bozhanov

unread,
Apr 16, 2014, 2:57:05 PM4/16/14
to jst...@googlegroups.com
disabled nodes cannot be selected, so the select_node event won't fire for those nodes. If you want them to be selectable - do not disable them, or if you want to do something when the disabled node is clicked just listen for:
$('#tree').on('click', '.jstree-disabled', function (e) {
  // do stuff
})

Best regards,
Ivan

Travas Nolte

unread,
Apr 17, 2014, 10:56:05 AM4/17/14
to jst...@googlegroups.com
Excellent. Thank you for pointing me in the right direction.
Reply all
Reply to author
Forward
0 new messages