3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
8 * @class Ext.tree.TreeFilter
9 * Note this class is experimental and doesn't update the indent (lines) or expand collapse icons of the nodes
10 * @param {TreePanel} tree
11 * @param {Object} config (optional)
13 Ext.tree.TreeFilter = function(tree, config){
16 Ext.apply(this, config);
19 Ext.tree.TreeFilter.prototype = {
26 * Filter the data by a specific attribute.
27 * @param {String/RegExp} value Either string that the attribute value
28 * should start with or a RegExp to test against the attribute
29 * @param {String} attr (optional) The attribute passed in your node's attributes collection. Defaults to "text".
30 * @param {TreeNode} startNode (optional) The node to start the filter at.
32 filter : function(value, attr, startNode){
33 attr = attr || "text";
35 if(typeof value == "string"){
36 var vlen = value.length;
37 // auto clear empty filter
38 if(vlen == 0 && this.clearBlank){
42 value = value.toLowerCase();
44 return n.attributes[attr].substr(0, vlen).toLowerCase() == value;
46 }else if(value.exec){ // regex?
48 return value.test(n.attributes[attr]);
51 throw 'Illegal filter type, must be string or regex';
53 this.filterBy(f, null, startNode);
57 * Filter by a function. The passed function will be called with each
58 * node in the tree (or from the startNode). If the function returns true, the node is kept
59 * otherwise it is filtered. If a node is filtered, its children are also filtered.
60 * @param {Function} fn The filter function
61 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Node.
63 filterBy : function(fn, scope, startNode){
64 startNode = startNode || this.tree.root;
68 var af = this.filtered, rv = this.reverse;
76 var m = fn.call(scope || n, n);
87 if(typeof id != "function"){
89 if(n && n.parentNode){
90 n.parentNode.removeChild(n);
98 * Clears the current filter. Note: with the "remove" option
99 * set a filter cannot be cleared.
103 var af = this.filtered;
105 if(typeof id != "function"){