kok体育官网下载链接


Produced By 中国煤炭开发有限责任公司
主页 > 公司要闻 >

Extjs4.x Ext.tree.Panel过滤Filter以及trigger field的使用示例

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

kok体育官网下载链接Tree节点筛选UI很简单,一个Tbar,一个trigger即可办理问题,剩下的是逻辑代码了。

kok体育官网下载链接1.tbar没啥好解析的

2.trigger几个对照紧张的属性

kok体育官网下载链接triggerCls:文本框右侧的按钮样式,主要有4种

x-form-clear-trigger// the X icon

x-form-search-trigger// the magnifying glass iconx-form-trigger// the down arrow (default for combobox) icon

x-form-date-trigger// the calendar icon (just in case)

kok体育官网下载链接onTriggerClick:单击右侧按钮的事故

emptyText:值为空时刻显示的翰墨

kok体育官网下载链接hideTrigger:是否显示触发按钮

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

kok体育官网下载链接3.剩下最紧张的一个是逻辑处置惩罚类

完备的案例代码如下:

Ext.define("WMS.view.Tree", {

kok体育官网下载链接extend: 'Ext.tree.Panel',

alias: 'widget.wmsTree',

id: 'wmsMenuTreePanel',

title: "功能导航",

margins: '0 0 0 3',

width: 200,

region: 'west',

kok体育官网下载链接animate: true,

kok体育官网下载链接store: 'VPTreeMenu',

kok体育官网下载链接autoScroll: true,

rootVisible: false,

loadMsg: true,

kok体育官网下载链接collapsible: true,//是否可以折叠

kok体育官网下载链接split: true,

tools: [{

type: 'expand',

handler: function () { Ext.getCmp("wmsMenuTreePanel").expandAll(); }

}, {

type: 'collapse',

kok体育官网下载链接handler: function () { Ext.getCmp("wmsMenuTreePanel").collapseAll(); }

}],

//这里不要忘怀

mixins: {

kok体育官网下载链接treeFilter: 'WMS.view.TreeFilter'

},

tbar: [{

xtype: 'trigger',

triggerCls: 'x-form-clear-trigger',

onTriggerClick: function () {

this.setValue('');

kok体育官网下载链接Ext.getCmp("wmsMenuTreePanel").clearFilter();

},

kok体育官网下载链接width:'100%',

emptyText:'快速检索功能',

enableKeyEvents: true,

listeners: {

keyup: {

fn: function (field, e) {

kok体育官网下载链接if (Ext.EventObject.ESC == e.getKey()) {

kok体育官网下载链接field.onTriggerClick();

} else {

kok体育官网下载链接Ext.getCmp("wmsMenuTreePanel").filterByText(this.getRawValue());

}

}

}

}

}]

});

/**

* Add basic filtering to Ext.tree.Panel. Add as a mixin:

*mixins: {

*treeFilter: 'WMS.view.TreeFilter'

*}

*/

kok体育官网下载链接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.

kok体育官网下载链接* @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.

kok体育官网下载链接// Then add them and their parents to nodesAndParents.

kok体育官网下载链接this.getRootNode().cascadeBy(function(tree, view){

kok体育官网下载链接var currNode = this;

kok体育官网下载链接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);

kok体育官网下载链接currNode = currNode.parentNode;

}

}

}, null, [me, view]);

kok体育官网下载链接// Hide all of the nodes which aren't in nodesAndParents

this.getRootNode().cascadeBy(function(tree, view){

var uiNode = view.getNodeByRecord(this);

kok体育官网下载链接if(uiNode && !Ext.Array.contains(nodesAndParents, this.id)) {

Ext.get(uiNode).setDisplayed('none');

}

kok体育官网下载链接}, null, [me, view]);

},

clearFilter: function() {

kok体育官网下载链接var view = this.getView();

this.getRootNode().cascadeBy(function(tree, view){

kok体育官网下载链接var uiNode = view.getNodeByRecord(this);

if(uiNode) {

Ext.get(uiNode).setDisplayed('table-row');

}

kok体育官网下载链接}, null, [this, view]);

}

});

假如你想对节点的中文做些处置惩罚,例如按照拼音首字母进行搜索,只必要变化如下这句代码即可

currNode.data[by].toString().toLowerCase().indexOf(text.toLowerCase()) > -1更多扩展,可以自己改动类 WMS.view.TreeFilter

Produced By 中国煤炭开发有限责任公司