2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
10 * @class Ext.tree.TreeFilter
\r
11 * Note this class is experimental and doesn't update the indent (lines) or expand collapse icons of the nodes
\r
12 * @param {TreePanel} tree
\r
13 * @param {Object} config (optional)
\r
15 Ext.tree.TreeFilter = function(tree, config){
\r
18 Ext.apply(this, config);
\r
21 Ext.tree.TreeFilter.prototype = {
\r
28 * Filter the data by a specific attribute.
\r
29 * @param {String/RegExp} value Either string that the attribute value
\r
30 * should start with or a RegExp to test against the attribute
\r
31 * @param {String} attr (optional) The attribute passed in your node's attributes collection. Defaults to "text".
\r
32 * @param {TreeNode} startNode (optional) The node to start the filter at.
\r
34 filter : function(value, attr, startNode){
\r
35 attr = attr || "text";
\r
37 if(typeof value == "string"){
\r
38 var vlen = value.length;
\r
39 // auto clear empty filter
\r
40 if(vlen == 0 && this.clearBlank){
\r
44 value = value.toLowerCase();
\r
46 return n.attributes[attr].substr(0, vlen).toLowerCase() == value;
\r
48 }else if(value.exec){ // regex?
\r
50 return value.test(n.attributes[attr]);
\r
53 throw 'Illegal filter type, must be string or regex';
\r
55 this.filterBy(f, null, startNode);
\r
59 * Filter by a function. The passed function will be called with each
\r
60 * node in the tree (or from the startNode). If the function returns true, the node is kept
\r
61 * otherwise it is filtered. If a node is filtered, its children are also filtered.
\r
62 * @param {Function} fn The filter function
\r
63 * @param {Object} scope (optional) The scope of the function (defaults to the current node)
\r
65 filterBy : function(fn, scope, startNode){
\r
66 startNode = startNode || this.tree.root;
\r
70 var af = this.filtered, rv = this.reverse;
\r
71 var f = function(n){
\r
78 var m = fn.call(scope || n, n);
\r
86 startNode.cascade(f);
\r
89 if(typeof id != "function"){
\r
91 if(n && n.parentNode){
\r
92 n.parentNode.removeChild(n);
\r
100 * Clears the current filter. Note: with the "remove" option
\r
101 * set a filter cannot be cleared.
\r
103 clear : function(){
\r
105 var af = this.filtered;
\r
107 if(typeof id != "function"){
\r
114 this.filtered = {};
\r