- 浏览: 152874 次
- 性别:
- 来自: 北京
最新评论
-
科小新:
99999999999999999
[Ext扩展]两个来自Ext官方论坛的时间控件扩展,可选择时分秒 -
ldl_xz:
http://www.9958.pw/post/css_pos ...
兼容ie6、ie7、ff的css顶端固定位置定位 -
snnosnno:
有浏览器差异吖
[Ext扩展]两个来自Ext官方论坛的时间控件扩展,可选择时分秒 -
lian819:
感谢无私分享了, 必须赞一个啊
[Ext扩展]两个来自Ext官方论坛的时间控件扩展,可选择时分秒 -
Sweetme:
放进项目就行了,成功了。谢谢哦怒赞
[Ext扩展]两个来自Ext官方论坛的时间控件扩展,可选择时分秒
有句老话叫不重复造轮子,既然网上已经有下拉树的扩展,为什么还要再做一个呢?答案很简单,网上那些满足不了我的需要。简单来说,本扩展UI组件具备以下功能:
示例放到Ext根路径下即可查看,内含详细使用说明,效果图如下:
Ext版本已测试3.1.1、3.2.0
IE6下页面显示问题解决方案:设置css如下
,Firefox、Chrome测试正常
源代码:
- 宽度自适应 下拉列表宽度可根据树的大小进行自动调整
- 延迟加载 默认采用,提高页面渲染速度
- 自动寻路 下拉列表展开时会将选中树结点的按其路径展开
- 键盘导航 支持使用上下左右回车ESC、TAB进行操作
- 智能过滤 支持使用汉字和拼音首字母对树进行过滤
- 默认值支持 可以为组件设置默认值,组件会自动找到对应结点
- 忽略父节点 默认情况只有选择子节点才有效
示例放到Ext根路径下即可查看,内含详细使用说明,效果图如下:
Ext版本已测试3.1.1、3.2.0
IE6下页面显示问题解决方案:设置css如下
body { font-size:13px; }(这是IE的问题,不用怀疑)
,Firefox、Chrome测试正常
源代码:
/** * * 支持功能: * 1.自动宽度和高度调整;弹出层会根据依据树的宽高调整自身宽高,注意:设置listWidth属性后弹出 * 层宽度将固定,树面板在需要时会出现水平滚动条;设置minListWidth属性可限定弹出层最小宽度, * 默认为TreeCombo的宽度; * 2.自动寻找选中结点:弹出层展开后会根据当前值找到对应结点并根据其树中路径展开树,其余结点将 * 收缩。 * 3.程序赋值:通过setValue(String nodeId);方法可通过代码设置TreeCombo的Value值,此时程序会 * 自动找到树节点id对应的树节点text并将其显示到输入域中,如果找不到对应树节点,输入域会显示 * 配置项valueNotFoundText的值提示这是个程序错误! * 4.自动检测:输入域默认是可以编辑的,ComboBox失去焦点后自动检测当前输入域中内容是否有对应的树 * 结点,有的话设置value值为对应结点,没有则自动退回到上一次失去焦点时的状态; * 5.键盘导航:down(选择上一节点)、up(选择下一结点)、enter(选中当前选择结点)、left(收 * 缩当前结点)、right(展开当前结点)、esc(取消编辑)、tab(取消编辑并跳转到下一个输入域); * 6.忽略父节点:ignoreFolder可设置父节点不能被选中,此属性为true时用户点击父节点时面板不会 * 收缩、过滤时也会忽略父节点; * 也不会被赋值,调用setValue方法时如果找到的是父节点输入域会显示配置项valueNotFoundText的值; * 7.拼音首字母过滤:用户对输入域编辑时树节点都会根据输入域中字母进行拼音首字母过滤,匹配结点 * 将保留并展开,内置缓存处理以提高多次查询的检索速度,可与键盘导航功能同时使用,最大限度提高 * 数据录入速度; * 8.延迟初始化:默认情况下lazyInit属性为true,此时tree会在TreeCombo获得焦点后才进行创建,这样做 * 可以提高页面加载速度。 * 9.可输入状态下输入域允许粘贴,失去焦点后组件会找到对应树节点并为值域(value)赋值,找不到显示组件 * 的emptyText * 10.默认值支持:如果需要默认值可以将结点id赋给value,默认情况下因为使用延迟加载,默认值只有在组件 * 获得焦点后才会通过树找到要结点text属性并显示到界面上,如果需要加载后就显示初始值可将lazyInit设置 * 为false * * 注意事项: * 1.如果树结点不是由root一次性加载,功能479将无法适用,此时请配置TreeCombo的editable属性为false; * 2.不同与官方的ComboBox,此下拉框没有forceSelection配置项(该配置项为false时用户可自定义下 * 拉框内容),因为我不知道允许用户自定义内容有什么意义; * 3.为ComboBox配置tree属性必须配置Object直接量对象(用{}来声明的对象)不能是new创建的实例, * TreeCombo会负责树对象的创建和销毁; * 4.树的根结点是不可见的,此时树在创建时就会执行root的expand方法开始加载其子结点,因而树的root * 结点必须以new Ext.tree.AsyncTreeNode方式进行声明,否则无法添加事件判断其加载完成状态。 * 5.如果树节点过多,过滤功能将严重影响性能,此时可设置 * * v1.1改动: * 1.添加一个配置项maxHeight用于控制列表的最大高度 * * @author chemzqm@gmail.com * @version 1.0.0 * @createTime 2010-04-24 16:40:30 * */ Ext.ns('QM.ui'); QM.ui.TreeCombo = Ext.extend(Ext.form.TriggerField, { shadow: 'sides', /** * @cfg minListWidth 弹出层最小宽度,必须大于ComboBox宽度,与listWidth同时使用时无效 */ /** * @cfg listWidth 弹出层固定宽度,设置后弹出层不根据树宽度进行调整,必须大于ComboBox宽度 * */ /** * @cfg hiddenName 隐藏表单域名,form方式提交时需要,负责把value传到后台 */ /** * @cfg listClass 阴影层样式 */ listAlign: 'tl-bl?', queryDelay:300,//查询函数缓冲时间(缓冲时间内再次调用将取消上次调用) valueNotFoundText: '没有指定数据', triggerAction: 'all',//下拉按钮点击时查询条件'all'查询出所有数据 'query'根据输入项进行前端匹配 ignoreFolder: true,//父节点不做为数据源 lazyInit: true,//控件获得焦点时才会初始化下拉框包括树 loadingText:'加载中...', emptyText:'请选择...', forceSelection: true,//输入框的值只能是列表存有的值 enableQuery : true, initComponent: function(){ this.hiddenPkgs = [];//隐藏的分支节点 QM.ui.TreeCombo.superclass.initComponent.call(this); this.addEvents('expand', 'collapse','beforeselect','select'); }, onRender: function(ct, position){ QM.ui.TreeCombo.superclass.onRender.call(this, ct, position); if(this.hiddenName){ this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName, id: (this.hiddenId||this.hiddenName)}, 'before', true); } if (this.lazyInit) { this.on('focus', this.initList, this, { single: true }); } else { this.initList(); } }, initEvents : function(){ QM.ui.TreeCombo.superclass.initEvents.call(this); this.keyNav = new Ext.KeyNav(this.el, { "up" : this.onKeyDown, "down" : function(e){ if (!this.isExpanded()) { this.onTriggerClick(); } else { this.onKeyDown(e); } }, "left":this.onKeyDown, "right":this.onKeyDown, "enter":function(){ var node = this.tree.selModel.getSelectedNode(); this.onTreeClick(node); }, "esc" : function(e){ this.collapse(); }, "tab" : function(e){ this.collapse(); return true; }, scope : this, forceKeyDown : true }); this.dqTask = new Ext.util.DelayedTask(this.initQuery, this); if(!this.enableKeyEvents){ this.mon(this.el, 'keyup', this.onKeyUp, this); } }, //上下左右回车让TreeSelectionModel来辅助实现 onKeyDown:function(e){ var sm = this.tree.getSelectionModel(); if(sm){ sm.onKeyDown(e); } this.el.focus(); }, initQuery:function(){ this.doQuery(this.getRawValue()); }, onKeyUp : function(e){ var k = e.getKey(); if(this.editable !== false && this.readOnly !== true && (k == e.BACKSPACE || !e.isSpecialKey())){ this.dqTask.delay(this.queryDelay); } Ext.form.ComboBox.superclass.onKeyUp.call(this, e); }, initList: function(){ if (!this.list) { var cls = 'x-combo-list', listParent = Ext.getDom(this.getListParent() || Ext.getBody()), zindex = parseInt(Ext.fly(listParent).getStyle('z-index'), 10); if (this.ownerCt && !zindex) {//找到父容器定义的z-index this.findParentBy(function(ct){ zindex = parseInt(ct.getPositionEl().getStyle('z-index'), 10); return !!zindex; }); } this.list = new Ext.Layer({ parentEl: listParent, shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain: false, zindex: (zindex || 12000) + 5 }); if(!this.minListWidth){ this.minListWidth = this.wrap.getWidth(); } this.list.setStyle('width', this.minListWidth); this.list.setStyle('height', 'auto'); this.list.swallowEvent('mousewheel'); this.innerList = this.list.createChild({ cls: cls + '-inner' }); this.initInner(); } }, initInner: function(){ Ext.apply(this.tree, { applyTo: this.innerList, border: false, rootVisible: false, autoScroll: true }); var root = this.tree.root; if(root instanceof Ext.tree.AsyncTreeNode){ root.on('beforeload',this.onBeforeRootLoad,this,{single:true}); root.on('load',this.onRootLoad,this,{single:true}); } this.tree = Ext.create(this.tree, 'treepanel'); this.tree.on({//加载完毕后再给树添加监听 scope: this, expandnode: this.onTreeResize, collapsenode: this.onTreeResize, click: this.onTreeClick }); if(this.editable){ this.filter = new QM.ux.TreeFilter(this.tree,{ ignoreFolder:this.ignoreFolder, clearAction:'collapse' }); } if(this.value) { this.setValue(this.value); } }, //@private onRootLoad:function(){ this.isLoading = false; if (this.value) { this.setValue(this.value); } this.innerList.child('.loading-indicator').remove(); if(this.isExpanded()){ this.onLoad(); } }, //@private onTreeResize:function(){ if(this.isExpanded()&&this.isQuerying!==true){ this.restrict(); this.el.focus(); } }, //@private onBeforeRootLoad : function(){ this.isLoading = true; this.innerList.insertFirst({ tag:'div', cls:'loading-indicator', html:this.loadingText }); }, //@private onLoad: function(){ if (!this.hasFocus) { return; } this.expand(); if(!this.selectByNode(this.value, true)){ this.selectByNode(this.tree.root.firstChild, true);//没有的话选中第一个结点 } if (this.editable) { this.el.focus(); } }, isExpanded: function(){ return this.list && this.list.isVisible(); }, expand: function(){ if (this.isExpanded() || !this.hasFocus) { return; } this.list.show(); this.mon(Ext.getDoc(), { scope: this, mousewheel: this.collapseIf, mousedown: this.collapseIf }); this.fireEvent('expand', this); }, collapseIf: function(e){ if (!e.within(this.wrap) && !e.within(this.list)) { this.collapse(); } }, //@public collapse: function(){ if (!this.isExpanded()) { return; } this.list.hide(); Ext.getDoc().un('mousewheel', this.collapseIf, this); Ext.getDoc().un('mousedown', this.collapseIf, this); this.fireEvent('collapse', this); }, //重置弹出层宽度 restrict: function(){ this.innerList.dom.style.width = '10px';//外层挤压,值太小会被Chrome忽略 var body = this.tree.body.dom; wpad = this.list.getFrameWidth('lr'),//边宽 wa = Math.max(body.clientWidth, body.offsetWidth, body.scrollWidth), w = Math.max(wa, this.minListWidth - wpad); w = this.listWidth ? this.listWidth : w; lh = this.list.getHeight(); h = (this.maxHeight&&this.maxHeight<lh)?this.maxHeight:lh;//获取高度 this.list.setHeight(h); this.innerList.setHeight(h); this.list.setWidth(w + wpad); this.innerList.setWidth(w); this.list.alignTo.apply(this.list, [this.el].concat(this.listAlign)); return; }, getListParent: function(){ return document.body; }, onTriggerClick: function(){ if (this.readOnly || this.disabled) { return; } if (this.isExpanded()) { this.collapse(); this.el.focus(); } else { this.onFocus({}); if(this.filter){ this.filter.clear(); } this.onLoad(); } }, doQuery: function(q){ q = Ext.isEmpty(q) ? '' : q; if (!this.isLoading && this.filter) { this.filter.filter(q); } if(this.filter.isCleared()){ this.tree.root.firstChild.select(); } else if(this.filter.hasMatch()){ this.filter.matches[0].select(); } this.el.focus(); this.expand(); this.restrict(); }, onTreeClick: function(node){ if(this.fireEvent('beforeselect', this, node) !== false){ if (this.ignoreFolder && !node.leaf) return; this.setValue(node); this.collapse(); this.fireEvent('select', this, node); } }, //@public 确保树已加载所需结点再调用此方法,如果传的是id但是找不到结点value域将置空 setValue: function(node){//根据TreeNode的id或者TreeNode对象设置值,显示TreeNode的text属性 if (!this.tree.rendered||this.isLoading) { return null; } if(typeof node == 'string'){ node = this.tree.getNodeById(node); } var text; if(!node||(this.ignoreFolder && !node.leaf)){ text = this.valueNotFoundText; } else { text = node.text; } QM.ui.TreeCombo.superclass.setValue.call(this, text); if(this.hiddenField){ this.hiddenField.value = node.id; } this.lastSelectionText = text; this.value = node?node.id:''; return this; }, getValue : function(){ return Ext.isDefined(this.value) ? this.value : ''; }, clearValue : function(){ if(this.hiddenField){ this.hiddenField.value = ''; } this.setRawValue(''); this.lastSelectionText = ''; this.value = ''; }, // private validateBlur : function(){ return !this.list || !this.list.isVisible(); }, //检查输入值是不是列表里有的,有的话设置对应value beforeBlur : function(){ var val = this.getRawValue(); node = this.tree.root.findChild('text',val,true); if(!node){ if(val.length > 0 && val != this.emptyText){ this.el.dom.value = Ext.value(this.lastSelectionText, '');//值空或是上一次输入 }else{//输入域清空,所有值清空 this.clearValue(); } }else if(node){ this.setValue(node); } }, //根据id值或node对象选择到相应node并显示出来,scrollIntoView是否需要滚动 selectByNode : function(node, scrollIntoView){ if(!Ext.isEmpty(node, true)){ if (typeof node == 'string') { node = this.tree.getNodeById(node); } if(node){ this.tree.collapseAll(); this.tree.expandPath(node.getPath());//只展开选中结点 node.select(); if(scrollIntoView===true) node.ensureVisible(); return true; } } return false; }, // private postBlur : function(){ QM.ui.TreeCombo.superclass.postBlur.call(this); this.collapse(); this.inKeyMode = false; }, onDestroy: function(){ if (this.dqTask){ this.dqTask.cancel(); this.dqTask = null; } Ext.destroy(this.tree,this.list,this.filter); QM.ui.TreeCombo.superclass.onDestroy.call(this); } }); Ext.reg('treecombo', QM.ui.TreeCombo);
评论
6 楼
lai555
2012-03-09
有没有文档呢,请问,比如我要得到选择的值
5 楼
jy02534655
2011-12-22
不晓得为啥用vs2010调试的时候不能加载远程数据,显示不出来数据。求解是ext3.20
4 楼
ahuixuan
2011-12-14
谢谢了!非常好的例子
3 楼
jrs320
2011-08-11
楼主辛苦了,我用了你这个控件,也做了些修改,很不错!现在有个问题:这个控件放在formpanel容器中,在加载表单时,这个控件无法初始对应的值(就是在控件渲染前,已经有值了,怎么显示初始值以及赋值),我至今还未找到解决的办法,希望楼主能解决下,非常感谢啊!
2 楼
zhangjunfun78
2011-07-21
支持楼主,辛苦了,这个控件非常好用,不过建议你将beforeBlur 方法中对应值的地方改为根据id对应,否则,如果出现同名的节点,下次就会自动选中第一个同名的节点。
1 楼
guyuelong2010
2011-06-28
楼主,谢谢了,用了挺好的,就是你这个最大高度,他不好使啊,当数据多时超过屏幕了就看不到底下的数据了,可以修改一下吗。
发表评论
-
[翻译]Ex4t教程:Ext4起步
2012-02-23 21:58 01.1 浏览器 Ext JS 4 supports a ... -
[Ext入门]如何学习Ext
2010-05-29 19:26 2714国内使用Ext的可谓不少,但是多数也只限与使用其中示例,真能把 ... -
[Ext重写]必填项的label后面加星号
2010-05-20 15:49 3204Ext.form.TextField.override({ ... -
[Ext重写]限制树的深度
2010-05-19 00:51 1881以前做政府项目的时候经常涉及行政区划的树,这个树有的时候要显示 ... -
[Ext源码]Ext的核心方法
2010-05-07 01:17 1541Ext.extend方法: extend : functi ... -
[Ext插件]QM.plugin.MutilTreeFilter:为树添加过滤、展开、收缩功能
2010-05-01 19:48 3587先来看看Ext的官方API的左上角 本插件基于Ext3.0 ... -
[Ext入门]图文详解Ext常见开发工具的安装使用
2010-04-27 21:28 4718俗话说,工欲善其事,必先利其器。缺乏好的工具想要用好Ext这么 ... -
[Ext扩展]动态分页大小、动态grid高度、本地数据分页三合一
2010-04-27 02:53 6332Ext.ux.plugins.PageComboResizer ... -
[Ext扩展]两个来自Ext官方论坛的时间控件扩展,可选择时分秒
2010-04-26 22:55 21703为方便大家使用,我把控件所需的js、css、gif文件都提取出 ... -
[Ext扩展]QM.ux.TreeFilter:树节点智能过滤,添加中文模糊匹配功能
2010-04-26 18:24 5720Ext自带一个Ext.tree.TreeFilter类,可以实 ... -
[组件用法]Ext.state.Manager对组件状态进行管理
2010-04-20 01:44 4885Ext.state.Manager存在的意义:简单说就是在客户 ... -
[Ext插件]PinyinFilter:使用拼音首字母对数据进行过滤
2010-04-19 00:37 3955这个插件的目的在于提高用户对于数据的选择效率。经常录入数据的人 ... -
[Ext扩展]根据后台json生成左侧导航菜单,5月9日更新1.1版本
2010-04-16 03:39 4919文章内不再提供示例,需要查看者请从SVN下载,地址: http ... -
[Ext扩展]MenuToolbar:根据json串生成多级菜单
2010-04-14 20:16 3739注意:html文件的Ext库引用请自行解决,效果图: ... -
[Ext扩展]JsonTreeLoader:一次加载所有树节点更新1.1版本
2010-04-14 19:58 4690仿照官网例子:XmlTreeLoader做的,下面有实例 注意 ... -
[组件用法]Ext.History用法要点
2010-04-14 01:11 2558在我的单页面试了下这个类的用法,发现这个类还是比较特殊的。 说 ... -
拒绝iframe嵌套,ajax方式轻松实现单页面
2010-04-13 00:00 6208以前单位做的项目都是上面一排菜单按钮,每点击一次按钮下面工作区 ... -
[Ext源码解读]事件的注册、添加与触发是如何实现的
2010-04-11 01:49 2142Ext提供了一套强大的事件处理机制,每个组件都有许多事件,用户 ... -
为Ext.Msg添加一个ghost提示的方法
2010-04-05 19:43 2041总觉得的老用alert的方式打断用户操作是非常不好的做法,调用 ... -
Ext.TreeNodeCascade让所有Ext的树支持级联选中
2010-04-05 04:15 6027运用了单例模式,使用的话直接让页面文件引用即可。该程序不直接关 ...
相关推荐
[Ext 3.x + Ext 2.x] 下拉树 Ext.ux.ComboBoxTree
EXT dojoChina按钮控件示例 Ext.Button.rarEXT dojoChina按钮控件示例 Ext.Button.rarEXT dojoChina按钮控件示例 Ext.Button.rarEXT dojoChina按钮控件示例 Ext.Button.rar
ExtJs3下拉树 分两种方式调用:第一种: xtype : 'combotree', name : 'dm', fieldLabel : 'dm', tree : this.ct this.ct = new Ext.tree.TreePanel({ autoScroll : true, height : 250, border : false, ...
jcifs-ext-0.9.4.jar/jcifs-1.3.3.jar 单点登陆 解决maven仓库有jar包但是maven程序无法下载仓库jar包
var reader = new Ext.data.JsonReader({totalProperty:'totalProperty',root:'root'},record); store = new Ext.data.Store({ proxy:proxy, reader:reader }); //尾 分页 var pagebar = new Ext....
EXT.JS_文档EXT.JS_文档EXT.JS_文档EXT.JS_文档EXT.JS_文档EXT.JS_文档EXT.JS_文档EXT.JS_文档EXT.JS_文档EXT.JS_文档EXT.JS_文档EXT.JS_文档EXT.JS_文档EXT.JS_文档EXT.JS_文档EXT.JS_文档EXT.JS_文档EXT.JS_文档...
Ext.ux.touch.DateTimePicker 该扩展通过扩展 Ext.Picker 为 Sencha Touch 框架提供了一个 DateTimePicker。用法datetimePicker = new Ext.ux.touch.DateTimePicker({ useTitles: true, id: 'dt', value: { day: 23,...
Ext.data.Store的基本用法 Ext.data.Store的基本用法 Ext.data.Store的基本用法
JMeter导入jmx运行脚本时出现这样的错误jmeter.save.SaveService: Conversion error .../lib/ext ==> JMeterPlugins.jar
Extjs4.1多个扩展 1、Ext.ux.aceeditor.Panel 2、Ext.ux.grid.feature.Tileview 3、Ext.ux.upload.Button 4、Ext.ux.toggleslide.ToggleSlide 5、Ext.ux.container.ButtonSegment 6、Ext.ux.grid.plugin.RowEditing ...
EXT dojochina文本框示例Ext.form.TextField.rar
简单的修改下Extjs 的引用路径 双击Index.html 就可以看到效果了。
EXT dojochina 面板示例Ext.Panel.rar EXT dojochina 面板示例Ext.Panel.rar
Apk Extractor_com.ext.ui.apk
Ext.3.0.中文Ext.3.0.中文Ext.3.0.中文Ext.3.0.中文Ext.3.0.中文Ext.3.0.中文Ext.3.0.中文Ext.3.0.中文
关于这个原因有很多种,我只说下我遇到的 我这样 写Store来复用的 代码如下: DocStore = Ext.extend(Ext.data.Store,{ initComponent:function(){ this.proxy = new Ext.data.HttpProxy({url:this.url}); this....
org.restlet.ext.servlet-2.1.1.jar
if (Ext.isIE6 || Ext.isIE7 || Ext.isSafari || Ext.isSafari2 || Ext.isSafari3) { var fd=Ext.get('frmDummy'); if (!fd) { fd=Ext.DomHelper.append(Ext.getBody(),{tag:'form',method:'post',id:'frmDummy'...
从spket IDE 官网下载。 文件名: ext-4.2.1.883.jsb2 对应版本ext-4.2.*版本。spket自动提示ExtJs4,需要ext4.2.1.jsp2文件。
extjs多选下拉框,Ext.ux.form.LovCombo,extjs 以修复多选下拉框火狐下取不到值的问题,火狐下div不显示背景色的问题