Limit search to only parent nodes

267 views
Skip to first unread message

Chris Malherbe

unread,
Apr 23, 2015, 4:24:21 AM4/23/15
to jst...@googlegroups.com
Guys,

Thank you for all the hard work you have done on jsTree it really works great.

I have a small problem with my implementation, we are rendering quite large trees, the leaf nodes are mostly named the same. This is because we have a lot of channels and ww can select the same units on all the channels.

The challenge however comes in when we search, if you for instance start the search with "k" the DOM crashes because there are so many matches on all the nodes. 

What I want to achieve is to have a search function that only searches the parent nodes never a leaf. There is a css attribute set to all the parent nodes that remove the check box. So basically I want to search only nodes without check-boxes.

I guess it will be something like this code, but I cant get it to work correctly:

.on('search.jstree before_open.jstree', function (e, data) {
                if(data.instance.settings.search.show_only_matches) {
                    data.instance._data.search.dom.find('.jstree-node')
                        .show().filter('.jstree-last').filter(function() { return this.nextSibling; }).removeClass('jstree-last')
                        .end().end().end().find(".jstree-children").each(function () { $(this).children(".jstree-node:visible").eq(-1).addClass("jstree-last"); });
                }
            }



 

Ivan Bozhanov

unread,
Apr 23, 2015, 11:34:13 AM4/23/15
to jst...@googlegroups.com
Take a look at the search_callback option - it bypasses the built in search completely and you can decide on a node per node basis which node is considered a match. Something like this (notice the leaves will not be marked):
http://jsfiddle.net/DGAF4/448/

Best regards,
Ivan
Reply all
Reply to author
Forward
0 new messages