Skip to content
Martin edited this page Nov 23, 2014 · 39 revisions

About Fancytree filter extension.

Allow to dimm or hide nodes based on a matching expression.

Options

  • autoApply, type: {boolean}, default: true
    Re-apply filter on lazy loading.

  • mode, type: {'dimm' | 'hide'}, default: 'dimm'
    Defines if unmatched nodes are grayed out or hidden.

Events

(n.a.)

Methods

  • {void} tree.clearFilter()
    Reset the filter.

  • {integer} tree.filterBranches(filter)
    Dimm or hide unmatched branches. Matching nodes are displayed together with all descendants.
    filter: {function | string}

  • {integer} tree.filterNodes(filter, leavesOnly)
    Dimm or hide unmatched nodes.
    filter: {function | string}
    leavesOnly {boolean}, default: false. Defines if only end nodes should be considered for matching.

Example

In addition to jQuery, jQuery UI, and Fancytree, include jquery.fancytree.filter.js:

  <script src="//code.jquery.com/jquery-1.11.1.min.js" type="text/javascript"></script>
  <script src="//code.jquery.com/ui/1.11.2/jquery-ui.min.js" type="text/javascript"></script>
  <link href="skin-win8/ui.fancytree.css" rel="stylesheet" type="text/css">
  <script src="js/jquery.fancytree.js" type="text/javascript"></script>
  <script src="js/jquery.fancytree.filter.js" type="text/javascript"></script>
$("#tree").fancytree({
  extensions: ["filter"],
  ...
});
// Case insensitive search for titles containing 'foo':
$("#tree").fancytree("getTree").filterNodes("foo");

// Restrict search to end nodes:
$("#tree").fancytree("getTree").filterNodes("foo", true);

For more complex searches, we can pass a compare function:

var rex = new RegExp("foo", "i");
$("#tree").fancytree("getTree").filterNodes(function(node) {
  return rex.test(node.title);
});

$("#tree").fancytree("getTree").filterNodes(function(node) {
  return node.data.customFlag === true;
});

We can match whole branches too:

$("#tree").fancytree("getTree").filterBranches(function(node) {
  return node.key === "abc";
});

Recipes

[Howto] ...
Clone this wiki locally