8

I can't figure this out for the life of me but I am trying to configure my JSTree to override the double click event so it is just single click event. Is this something added to the callback configuration? I am not sure how to do this, will I need to edit the JSTree source code? Documentation here: http://docs.planbleu.org/modules/webportal/jquery/jsTree.v.0.9.5/documentation/#configuration

I tried changing the "ondblclk" to "click" in the source code and then adding a "click" callback option to the config settings and it did nothing... I am probably doing it wrong though.

MetaGuru
  • 42,847
  • 67
  • 188
  • 294

5 Answers5

7

sending this into the tree creation function did the trick:

   onselect: function(n, t) {
         t.toggle_branch(n);
    },

(where t is the reference to the tree)

MetaGuru
  • 42,847
  • 67
  • 188
  • 294
6

I found the correct answer in an issue for the plugin on github. The above answers do NOT work. This absolutely works and is a comprehensive answer on how to call the plugin, and how to make it use single-click expand instead of double-click.

    $('#jstree')
        .on('click', '.jstree-anchor', function (e) {
            $(this).jstree(true).toggle_node(e.target);
        })
        .jstree()

Here is a link to where the author mentions the solution, in case you need it.

nfriend21
  • 2,170
  • 1
  • 21
  • 21
6
$("#tree").bind("select_node.jstree", function (e, data) {
 $("#tree").jstree("toggle_node", data.rslt.obj);
 $("#tree").jstree("deselect_node", data.rslt.obj);
});

This might get you started in the right direction. You'll probably need to filter out which ones to expand or not depending on meta data.

Or Arbel
  • 2,965
  • 2
  • 30
  • 40
Will Shaver
  • 12,471
  • 5
  • 49
  • 64
0
  $fullIndex.on('select_node.jstree', function(e, data){
    data.instance.toggle_node(data.selected);
  })
  .jstree()
rayking
  • 489
  • 4
  • 9
0
 $("#your_id_where_Tree").on('select_node.jstree', function(e, data){
       data.instance.toggle_node(data.selected);
 });
jmp
  • 2,456
  • 3
  • 30
  • 47
  • Code-only answers are generally frowned upon on this site. Could you please edit your answer to include some comments or explanation of your code? Explanations should answer questions like: What does it do? How does it do it? Where does it go? How does it solve OP's problem? See: [How to anwser](https://stackoverflow.com/help/how-to-answer). Thanks! – Eduardo Baitello Dec 17 '19 at 14:44