vakata/jstree

jstree search + checkbox improvement request

Closed this issue · 3 comments

Hello,

first, a fantastic plugin.

I'm more a networks and python person and not well versed with js. Working on some kind of middleware which needs to display the network equipment tree (city-site-building-closet etc) and that plugin fits very nicely. Search is quite quick for ~12000 leaf nodes, too, and the data loaded as the whole json block from some API.

I can find all checked boxes through this: var selectedNodes = $('#treeview_json').jstree("get_selected", false);

What I'm trying to do is check all the nodes which are marked as "found" in the search (class = jstree-search ? ) and as checkbox on them.

What would be the quickest way to change the check states based on the search result? May be, a couple of functions like set_search_checkboxes (to set the checkboxes for the nodes which are marked as found) and unset_search_checkboxes will be useful as the part of the jstree search?

Thanks

continuation from above.

I spent some time today on that issue and I could not find what jstree object attributes are updated for the nodes which are matching the search pattern. I was dumping an object to the console to see the content but nothing remotely related to search. I suspect that only the web document classes are updated through: this._data.search.dom.children(".jstree-anchor").addClass('jstree-search');

Would it be possible to introduce another state {'matched' : true/false } to reflect the search state of the tree elements?
I started playing with that but that would probably take quite some time for me to add

image

you may change the state of checkbox by jquery .prop("checked", true or false)

vakata commented

You can use the search.jstree event:
http://127.0.0.1/jstree/docs/#/api/?q=search.jstree&f=search.jstree

Something like:

$('#tree_container').on('search.jstree', function (e, data) { data.instance.check_node(data.res); }