Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom search for jQuery FancyTree plugin

I'm using the FancyTree jQuery plugin in one of my projects: https://github.com/mar10/fancytree

This plugin also has a Filter extension which either dimms or hides the unmatched nodes: https://github.com/mar10/fancytree/wiki/ExtFilter

My tree is a two-level tree, it means that there are folders which have children. What I try to do is - search by both Folder name and nodes names. The problem is that when you have something like this:

Node Title - Node child - Node child 2

Searching by "Title" will leave the folder "Node Title" and hide the children since there's no "Title" in them.

What I want to do is - search by both folder name and children names but don't hide the children - hide the unmatched folders only.

So, when you search by "Title" - it will hide all the folders which do not have "Title" in them but leave the child nodes of "Node Title" folder intact - visible.

Could anybody help me with an advise on how can this be done?

Thanks beforehand!

like image 239
cycero Avatar asked May 08 '14 13:05

cycero


2 Answers

This new feature has just been implemented: https://github.com/mar10/fancytree/wiki/ExtFilter

Look for the tree.filterBranches(filter) method.

like image 155
mar10 Avatar answered Oct 13 '22 12:10

mar10


I had exactly the same problem and google brought me here. It took me some time to understand this answer. You have to replace the filterNodes(...) in the sample with filterBranches(...). The internal function can stay exactly the same.

like image 43
guest Avatar answered Oct 13 '22 12:10

guest