Extjs5 tree扩展----treepanel树组件

 Ext.define( 'MyExtend.lib.TreeFilter' , {
        filterByText:  function (text) {
             this .filterBy(text,  'text'  );
        },
         /**
          *  根据字符串过滤所有的节点,将不符合条件的节点进行隐藏.
          *  @param  查询字符串.
          *  @param  要查询的列.
          */
        filterBy:  function (text, by) {
    
             this .clearFilter();
    
             var  view =  this  .getView(),
                me =  this ,
                nodesAndParents = [];
    
             // 找到匹配的节点并展开.
             // 添加匹配的节点和他们的父节点到nodesAndParents数组.
             this .getRootNode().cascadeBy( function (tree, view) {
                 var  currNode =  this ;
  //    alert(currNode.data[by]+'  '+by+'  '+text);
                 if  (currNode && currNode.data[by] && currNode.data[by].toString().toLowerCase().indexOf(text.toLowerCase()) > -1) {
                    me.expandPath(currNode.getPath());
    
                     while  (currNode.parentNode) {
                        nodesAndParents.push(currNode.id);
                        currNode = currNode.parentNode;
                    }
                }
            },  null , [me, view]);
    
             // 将不在nodesAndParents数组中的节点隐藏
             this .getRootNode().cascadeBy( function (tree, view) {
                 var  uiNode = view.getNodeByRecord( this );
    
                 if  (uiNode && !Ext.Array.contains(nodesAndParents,  this  .id)) {
                    Ext.get(uiNode).setDisplayed(  'none' );
                }
            },  null , [me, view]);
        },
    
    
        clearFilter:  function () {
             var  view =  this  .getView();
    
             this .getRootNode().cascadeBy( function (tree, view) {
                 var  uiNode = view.getNodeByRecord( this );
    
                 if  (uiNode) {
                    Ext.get(uiNode).setDisplayed( 'table-row'  );
                }
            },  null , [ this  , view]);
        }
    });
    Ext.define( 'MyTreePanel' ,{
        extend:  'Ext.tree.Panel' ,
        mixins:[  'MyExtend.lib.TreeFilter' ]
        
    });
 
  var  treePanel = Ext.create(  'MyTreePanel' , {
        id:  'tree-panel' ,
        title:  'Sample Layouts' ,
        region:  'center' ,
        split:  true ,
        height: 360,
        minSize: 150,
        rootVisible:  false ,
        autoScroll:  true ,
        store: store
    });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值