Ext.tree.TreeSorter=function(tree,config){
Ext.apply(this,config);
tree.on("beforechildrenrendered",this.doSort,this);
tree.on("append",this.updateSort,this);
tree.on("insert",this.updateSort,this);
tree.on("textchange",this.updateSorrtParent,this);
var dsc=this.dir && this.dir.tolowerCase()=="desc";
var p=this.property||"text";
var sortType=this.sortType;
var fs=this.folerSort;
var cs=this.caseSensitive==true;
var leafAttr=this.leafAttr ||'leaf';
this.sortFn=function(n1,n2){
if(fs){
if(n1.attributes[leafAttr]&& !n2.attributes[leafAttr]){
return 1;
if(!n1.attributes[leafAttr] && !n2.attributes[leafAttr]){
return -1;}}
var v1=sortType? sortType(n1):
(cs? n1.attributes[p]:n1.attributes[p].toupperCase());
var v2=sortType?sortType(n2);
(cs? n2.attributes[p]:n2.attributes[p].toUpperCase());
if(v1<v2){ return dsc? +1:-1;}
else(return 0;}};};
filterBy:function(fn,scope,startNode){
startNode=startNode||this.tree.root;
if(this.autoClear){this.clear();}
var af=this.filtered,rv=this.reverse;
var f=function(n){
if(n=startNode){return true;}
if(af[n.id]) {return false;}
var m=fn.call(scope||n,n);
if(!m||rv){
af[n.id]=n;
n.ui.hide();
return false;}
return true;};
startNode.cascade(f);
if(this.remove){
for(var id in af){
if(typeof id!="function"){
var n=af[id];
if(n && n.parentNode){n.parentNode.removeChild(n);}}}}