3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
14 <div id="cls-Ext.tree.TreeFilter"></div>/**
15 * @class Ext.tree.TreeFilter
16 * Note this class is experimental and doesn't update the indent (lines) or expand collapse icons of the nodes
17 * @param {TreePanel} tree
18 * @param {Object} config (optional)
20 Ext.tree.TreeFilter = function(tree, config){
23 Ext.apply(this, config);
26 Ext.tree.TreeFilter.prototype = {
32 <div id="method-Ext.tree.TreeFilter-filter"></div>/**
33 * Filter the data by a specific attribute.
34 * @param {String/RegExp} value Either string that the attribute value
35 * should start with or a RegExp to test against the attribute
36 * @param {String} attr (optional) The attribute passed in your node's attributes collection. Defaults to "text".
37 * @param {TreeNode} startNode (optional) The node to start the filter at.
39 filter : function(value, attr, startNode){
40 attr = attr || "text";
42 if(typeof value == "string"){
43 var vlen = value.length;
44 // auto clear empty filter
45 if(vlen == 0 && this.clearBlank){
49 value = value.toLowerCase();
51 return n.attributes[attr].substr(0, vlen).toLowerCase() == value;
53 }else if(value.exec){ // regex?
55 return value.test(n.attributes[attr]);
58 throw 'Illegal filter type, must be string or regex';
60 this.filterBy(f, null, startNode);
63 <div id="method-Ext.tree.TreeFilter-filterBy"></div>/**
64 * Filter by a function. The passed function will be called with each
65 * node in the tree (or from the startNode). If the function returns true, the node is kept
66 * otherwise it is filtered. If a node is filtered, its children are also filtered.
67 * @param {Function} fn The filter function
68 * @param {Object} scope (optional) The scope of the function (defaults to the current node)
70 filterBy : function(fn, scope, startNode){
71 startNode = startNode || this.tree.root;
75 var af = this.filtered, rv = this.reverse;
83 var m = fn.call(scope || n, n);
94 if(typeof id != "function"){
96 if(n && n.parentNode){
97 n.parentNode.removeChild(n);
104 <div id="method-Ext.tree.TreeFilter-clear"></div>/**
105 * Clears the current filter. Note: with the "remove" option
106 * set a filter cannot be cleared.
110 var af = this.filtered;
112 if(typeof id != "function"){