4

Has someone any idea if it's possible and how to search for all occurences of a keyword in the tree, expand and highlight all the results and their path to the root element.

I've found already an example for a single search here: https://github.com/mbraak/jqTree/issues/211

$('#search').click(
function() {
    var $tree = $('#tree1');
    var search_term = 'xyz';

    var tree = $tree.tree('getTree');

    tree.iterate(
        function(node) {
            if (node.name.indexOf(search_term) == -1) {
                // Not found, continue searching
                return true;
            }
            else {
                // Found. Select node. Stop searching.
                $tree.tree('selectNode', node, true);
                return false
            }
        }
    );
}
);

Thank you in advance!

SOLVED!

1 Answers1

2

Just don't stop searching when you found something.

    tree.iterate(
    function(node) {
        if (node.name.indexOf(search_term) >= 0) {
            // Found. Select node. Do not stop searching.
            $tree.tree('selectNode', node, true);
            return true; // I think that might be optional
        }
    }

You'll also have to configure your tree to automatically open nodes when selected.

Evren Kuzucuoglu
  • 3,781
  • 28
  • 51