4 * Copyright(c) 2006-2007, Ext JS, LLC.
6 * Originally Released Under LGPL - original licence link has changed is not relivant.
9 * <script type="text/javascript">
13 * @class Roo.tree.TreeFilter
14 * Note this class is experimental and doesn't update the indent (lines) or expand collapse icons of the nodes
15 * @param {TreePanel} tree
16 * @param {Object} config (optional)
18 Roo.tree.TreeFilter = function(tree, config){
21 Roo.apply(this, config);
24 Roo.tree.TreeFilter.prototype = {
31 * Filter the data by a specific attribute.
32 * @param {String/RegExp} value Either string that the attribute value
33 * should start with or a RegExp to test against the attribute
34 * @param {String} attr (optional) The attribute passed in your node's attributes collection. Defaults to "text".
35 * @param {TreeNode} startNode (optional) The node to start the filter at.
37 filter : function(value, attr, startNode){
38 attr = attr || "text";
40 if(typeof value == "string"){
41 var vlen = value.length;
42 // auto clear empty filter
43 if(vlen == 0 && this.clearBlank){
47 value = value.toLowerCase();
49 return n.attributes[attr].substr(0, vlen).toLowerCase() == value;
51 }else if(value.exec){ // regex?
53 return value.test(n.attributes[attr]);
56 throw 'Illegal filter type, must be string or regex';
58 this.filterBy(f, null, startNode);
62 * Filter by a function. The passed function will be called with each
63 * node in the tree (or from the startNode). If the function returns true, the node is kept
64 * otherwise it is filtered. If a node is filtered, its children are also filtered.
65 * @param {Function} fn The filter function
66 * @param {Object} scope (optional) The scope of the function (defaults to the current node)
68 filterBy : function(fn, scope, startNode){
69 startNode = startNode || this.tree.root;
73 var af = this.filtered, rv = this.reverse;
81 var m = fn.call(scope || n, n);
92 if(typeof id != "function"){
94 if(n && n.parentNode){
95 n.parentNode.removeChild(n);
103 * Clears the current filter. Note: with the "remove" option
104 * set a filter cannot be cleared.
108 var af = this.filtered;
110 if(typeof id != "function"){