Murali Mopuru Murali Mopuru - 2 months ago 11x
jQuery Question

jstree showing all nodes if search string didn't match any node

I'm rendering jstree with following config

'core': {
'data': data
'search': {
'case_insensitive': true,
'show_only_matches' : true
'plugins': ['search']

$('#deliverables').jstree('search', $(this).val());

With this config, jstree showing only matched nodes if the search text has found atleast one node. But jstree showing all the nodes if the search text not matching with any node. I found this a bit strange. Am i missing something here? link for your reference.


It's an intended bahavior, see:

But you can attach an handler to the search event and if the result is empty act accordingly, eg. you can hide the all the tree nodes using hide_all method.


.on('search.jstree', function (nodes, str, res) {
    if (str.nodes.length===0) {

But don't forget to show them all before trigger a new search:

    $('#deliverables').jstree('search', $(this).val());