Filtering
Filtering on the tree is not trivial, since the filtering process needs the keep the tree structure.
For example, if one of the nodes is visible - we must display its parent, and grandparent etc.
This is being taken care of by the treeModel 'filterNodes' function.
Filter by function
The function receives the node and returns true if the node should be hidden, false otherwise.
tree.treeModel.filterNodes((node) => {
return !node.data.name.startsWith(text);
});
Filter by string
The function filters all nodes whose displayField ('name' by default) contains the given string. The comparison is done case insensitive.
tree.treeModel.filterNodes("text", true);
Note the second field - true. This flag makes sure all nodes are visible after searching (i.e. expand all relevant ancestors).
Manual filtering
The filterNodes
function works with the isHidden
attribute on the nodes.
If you need a different behaviour than the above, you can traverse the tree and do your own magic, and set the isHidden
field on all nodes as you wish.
Note:
isHidden
is configurable via the isHiddenField
property of the options object.
Updated less than a minute ago