Extjs4.x中已经取消了组件Ext.Tree.TreeFilter功能,却掉了树形结构的过滤功能,要实现该功能只能自己写了.

Tree节点筛选UI很简单,一个Tbar,一个trigger即可解决问题,剩下的是逻辑代码了。

1.tbar没啥好解析的

2.trigger几个比较重要的属性

  triggerCls:文本框右侧的按钮样式,主要有4种  

x-form-clear-trigger     // the X icon
x-form-search-trigger // the magnifying glass icon
x-form-trigger // the down arrow (default for combobox) icon
x-form-date-trigger // the calendar icon (just in case)

  onTriggerClick:单击右侧按钮的事件

  emptyText:值为空时候显示的文字

  hideTrigger:是否显示触发按钮

  更多请参考:http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.field.Trigger-cfg-hideTrigger

3.剩下最重要的一个是逻辑处理类

完整的案例代码如下:

Ext.define("WMS.view.Tree", {
extend: 'Ext.tree.Panel',
alias: 'widget.wmsTree',
id: 'wmsMenuTreePanel',
title: "功能导航",
margins: '0 0 0 3',
width: 200,
region: 'west',
animate: true,
store: 'VPTreeMenu',
autoScroll: true,
rootVisible: false,
loadMsg: true,
collapsible: true,//是否可以折叠
split: true,
tools: [{
type: 'expand',
handler: function () { Ext.getCmp("wmsMenuTreePanel").expandAll(); }
}, {
type: 'collapse',
handler: function () { Ext.getCmp("wmsMenuTreePanel").collapseAll(); }
}],
  //这里不要忘记
mixins: {
treeFilter: 'WMS.view.TreeFilter'
},
tbar: [{
xtype: 'trigger',
triggerCls: 'x-form-clear-trigger',
onTriggerClick: function () {
this.setValue('');
Ext.getCmp("wmsMenuTreePanel").clearFilter();
},
width:'100%',
emptyText:'快速检索功能',
enableKeyEvents: true,
listeners: {
keyup: {
fn: function (field, e) {
if (Ext.EventObject.ESC == e.getKey()) {
field.onTriggerClick();
} else {
Ext.getCmp("wmsMenuTreePanel").filterByText(this.getRawValue());
}
}
}
}
}]
});

  

/**
* Add basic filtering to Ext.tree.Panel. Add as a mixin:
* mixins: {
* treeFilter: 'WMS.view.TreeFilter'
* }
*/
Ext.define('WMS.view.TreeFilter', {
filterByText: function(text) {
this.filterBy(text, 'text');
},
/**
* Filter the tree on a string, hiding all nodes expect those which match and their parents.
* @param The term to filter on.
* @param The field to filter on (i.e. 'text').
*/
filterBy: function(text, by) {
this.clearFilter();
var view = this.getView(),
me = this,
nodesAndParents = [];
// Find the nodes which match the search term, expand them.
// Then add them and their parents to nodesAndParents.
this.getRootNode().cascadeBy(function(tree, view){
var currNode = this; 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]);
// Hide all of the nodes which aren't in 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]);
}
});

 如果你想对节点的中文做些处理,例如按照拼音首字母进行搜索,只需要变更如下这句代码即可

currNode.data[by].toString().toLowerCase().indexOf(text.toLowerCase()) > -1

更多扩展,可以自己修改类 WMS.view.TreeFilter

Extjs4.x Ext.tree.Panel 过滤Filter以及trigger field的使用的更多相关文章

  1. Extjs4.x Ext.tree.Panel 遍历当前节点下的所有子节点

    Ext.define('WMS.controller.Org', { extend: 'Ext.app.Controller', stores: ['OrgUser', 'OrgTree'], mod ...

  2. Extjs学习笔记--Ext.tree.Panel

    Ext.create('Ext.tree.Panel', { title: 'Simple Tree', width: 200, height: 150, store: store, rootVisi ...

  3. Ext.tree.Panel Extjs 在表格中添加树结构,并实现节点移动功能

    最近在用Extjs 做后台管理系统,真的非常好用.总结的东西分享一下. 先展示一下效果图 好了,开始吧! 首先说一下我的创建结构: 一.构造内容 这个函数中包括store的创建,treePanel的创 ...

  4. Ext.tree.Panel实现单选,多选

    Extjs var productCategoryTreeLookUpFn = function(callback) { var productCategoryLookUpWindow; var pr ...

  5. ExtJS4.2 Ext.grid.panel Store更改后刷新表格

    //////////////////////// // Prepare store //////////////////////// // prepare fields and columns var ...

  6. Ext.tree.Panel

    initComponent : function() { var data = null;        Ext.Ajax.request({            url : 'xxx/xx',   ...

  7. EXTJS4扩展实例:如何使用filter查询treepanel

    我们在使用普通的store时,extjs提供了filterBy,filter等多种方法来过滤数据达到查询效果,但在treepanel中的streeStore却没有实现这个查询,于是,就有了这篇文章. ...

  8. Extjs-树 Ext.tree.TreePanel 动态加载数据

    先上效果图 1.说明Ext.tree.Panel 控件是树形控件,大家知道树形结构在软件开发过程中的应用是很广泛的,树形控件的数据有本地数据.服务器端返回的数据两种.对于本地数据的加载,在extjs的 ...

  9. ExtJS 4 在Ext.tab.Panel中使用Ext.ux.IFrame打开url指向的网页

    ext-4.2.1.883\examples\ux\IFrame.js ext-4.2.1.883\examples\ux\TabCloseMenu.js 复制到 \Scripts\ext-4.2.1 ...

随机推荐

  1. Python dict 出现 Key error

    解决方法: https://www.polarxiong.com/archives/Python-%E6%93%8D%E4%BD%9Cdict%E6%97%B6%E9%81%BF%E5%85%8D%E ...

  2. [转] spring的普通类中如何取session和request对像

    在使用spring时,经常需要在普通类中获取session,request等对像.比如一些AOP拦截器类,在有使用struts2时,因为struts2有一个接口使用org.apache.struts2 ...

  3. List遍历Java 8 Streams map() examples

    1. A List of Strings to Uppercase 1.1 Simple Java example to convert a list of Strings to upper case ...

  4. ext: gridpanel中的点击事件的参数是什么意思?

    listeners: {      // 当用户单击列表项时激发该函数      itemclick: function(view, record, item, index, evt)  //①    ...

  5. Android应用的基本原理

    原文:http://android.eoe.cn/topic/android_sdk 应用基础-Application Fundamentals Android应用程序以java作为开发语言.用And ...

  6. [svc]mount命令及解决因/etc/fstab错误导致系统不能启动故障

    mount命令-手动挂载设备 格式: mount [options] [-t fstype] [-o option] 设备 挂载点 mount -n -o remount,rw / - Mount t ...

  7. [svc]centos6上部署openvpn+gg二步认证

    最近又发现个新的vpn: wireguard 为了满足员工在家办公的需求.需要 openvpn+gg方案 在centos6上部署openvpn 参考 1.安装前准备 wget -O /etc/yum. ...

  8. 【Unity】8.1 Unity内置的UI控件

    分类:Unity.C#.VS2015 创建日期:2016-04-27 一.简介 Unity 5.x内置了-套完整的GUI系统,提供了从布局.控件到皮肤的-整套GUI解决方案,因此可直接利用它做出各种风 ...

  9. FFmpeg编译: undefined reference to 'av_frame_alloc()'

    今天使用CMake编译FFmpeg的时候,死活编不过,提示什么“undefined reference to 'av_frame_alloc()” 后来仔细查找,发现是头文件包含错误. 错误的代码: ...

  10. (原创)拨开迷雾见月明-剖析asio中的proactor模式(一)

    使用asio之前要先对它的设计思想有所了解,了解设计思想将有助于我们理解和应用asio.asio是基于proactor模式的,asio的proactor模式隐藏于大量的细节当中,要找到它的踪迹,往往有 ...