javascriptjstreejstree-search

JStree Search doesn't show up


My HTML has the scripts for jstree.search.js as well as jstree.js and I call jstree() like this:

tree = $('.jstree').jstree({
    core: {
        "check_callback" : true,
        "themes" : { "stripes" : true },
        },
      
    "plugins" : [
        "search", "state", "types"
      ]
    });

I can tell the state works, but the search simply doesn't seem to do anything. I was expecting for a search bar to appear, but there is none.

What am I doing wrong?


Solution

  • Nothing wrong: you have to include the search bar yourself.

    var $tree = $("#mytree");
    var $input = $(
      "<input type='search' placeholder='Search' />"
    );
    $input.insertBefore($tree);
    $input.on("keyup", function() {
      $tree.jstree(true).search($(this).val());
    });
    

    Enabling the plugin just allows to use the .search method.