Extjs4.x Ext.tree.Panel 过滤Filter以及trigger field的使用
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的使用的更多相关文章
- Extjs4.x Ext.tree.Panel 遍历当前节点下的所有子节点
Ext.define('WMS.controller.Org', { extend: 'Ext.app.Controller', stores: ['OrgUser', 'OrgTree'], mod ...
- Extjs学习笔记--Ext.tree.Panel
Ext.create('Ext.tree.Panel', { title: 'Simple Tree', width: 200, height: 150, store: store, rootVisi ...
- Ext.tree.Panel Extjs 在表格中添加树结构,并实现节点移动功能
最近在用Extjs 做后台管理系统,真的非常好用.总结的东西分享一下. 先展示一下效果图 好了,开始吧! 首先说一下我的创建结构: 一.构造内容 这个函数中包括store的创建,treePanel的创 ...
- Ext.tree.Panel实现单选,多选
Extjs var productCategoryTreeLookUpFn = function(callback) { var productCategoryLookUpWindow; var pr ...
- ExtJS4.2 Ext.grid.panel Store更改后刷新表格
//////////////////////// // Prepare store //////////////////////// // prepare fields and columns var ...
- Ext.tree.Panel
initComponent : function() { var data = null; Ext.Ajax.request({ url : 'xxx/xx', ...
- EXTJS4扩展实例:如何使用filter查询treepanel
我们在使用普通的store时,extjs提供了filterBy,filter等多种方法来过滤数据达到查询效果,但在treepanel中的streeStore却没有实现这个查询,于是,就有了这篇文章. ...
- Extjs-树 Ext.tree.TreePanel 动态加载数据
先上效果图 1.说明Ext.tree.Panel 控件是树形控件,大家知道树形结构在软件开发过程中的应用是很广泛的,树形控件的数据有本地数据.服务器端返回的数据两种.对于本地数据的加载,在extjs的 ...
- 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 ...
随机推荐
- 【转载整理】Hibernater的锁机制
转载原文:http://www.cnblogs.com/otomedaybreak/archive/2012/01/27/2330008.html 概要:数据库事务,事务并发,hibernate悲观锁 ...
- ROC 曲线简要解释
阳性 (P, positive)阴性 (N, Negative)真阳性 (TP, true positive):正确的肯定.又称:命中 (hit)真阴性 (TN, true negative):正确的 ...
- SQL Server 2008 附加数据库之后显示为 只读 的解决方法
嗯,附加完成后,数据库的灰色的,后面括号里写着(只读). 方法一: 碰到这中情况一般是使用的 sa 或者其它 SQL Server 身份验证登录的,只要改为 Windows 身份验证,再附加数据库即可 ...
- 设计模式-单例模式(Singleton Pattren)(饿汉模式和懒汉模式)
单例模式(Singleton Pattren):确保一个类在整个应用中只有一个实例,并提供一个全局访问点. 实现要点: 1. 私有化构造方法 2. 类的实例在类初始化的时候创建 3. 提供一个类方法, ...
- c语言实现xor加密
异或运算:^ 定义:它的定义是:两个值相同时,返回false,否则返回true.也就是说,XOR可以用来判断两个值是否不同. 特点:如果对一个值连续做两次 XOR,会返回这个值本身. ^ // 第一次 ...
- PHP将CMYK颜色值和RGB颜色相互转换的例子
PHP将CMYK颜色值和RGB颜色相互转换的例子 function hex2rgb($hex) { $color = str_replace('#','',$hex); $rgb = array('r ...
- Atitti dbutil获取多个返回结果集的解决
Atitti dbutil获取多个返回结果集的解决 1.1. 多个select默认只返回第一个resultset1 1.2. 调用存储过程,也是返回第一个select的1 1.3. 如果insert前 ...
- mac 上面安装jdk 1.6
下载地址 https://support.apple.com/kb/dl1572?locale=zh_CN orcale 支持mac的最低版本是1.7
- Apache Flink Training and sample code
http://training.data-artisans.com/ https://github.com/dataArtisans/blog-post-code-samples https://gi ...
- vscode 换行符\n 变成\r\n
VSCode是一个开源的强大代码编写器,但是如果没有好好的配置使用,会适得其反. 这里总结VSCode的一些配置,方便自己查询,也方便网友. 1.编辑器配置 为特定类型文件指定缩进大小.缩进类型(空格 ...