这是一个查找控件,实例的时候,需要指定一个store就可以,大家可以试下
Ext.app.SearchField = Ext.extend(Ext.form.TwinTriggerField, { initComponent : function(){ Ext.app.SearchField.superclass.initComponent.call(this); this.on('specialkey', function(f, e){ if(e.getKey() == e.ENTER){ this.onTrigger2Click(); } }, this); }, validationEvent:false, validateOnBlur:false, trigger1Class:'x-form-clear-trigger', trigger2Class:'x-form-search-trigger', hideTrigger1:true, width:180, hasSearch : false, paramName : 'query', onTrigger1Click : function(){ if(this.hasSearch){ this.el.dom.value = ''; var o = {start: 0}; this.store.baseParams = this.store.baseParams || {}; this.store.baseParams[this.paramName] = ''; this.store.reload({params:o}); this.triggers[0].hide(); this.hasSearch = false; } }, onTrigger2Click : function(){ var v = this.getRawValue(); if(v.length < 1){ this.onTrigger1Click(); return; } // var o = {start: 0}; // this.store.baseParams = this.store.baseParams || {}; // this.store.baseParams[this.paramName] = v; this.store.reload(); this.hasSearch = true; this.triggers[0].show(); } }); Ext.reg('searchfield',Ext.app.SearchField);
这是查找后可清空内容的控件,不需要指定store,适用于需要打开一个窗口选择数据时的应用
Ext.app.clearTriggerField = Ext.extend(Ext.form.TwinTriggerField, { initComponent : function(){ Ext.app.SearchField.superclass.initComponent.call(this); this.on('specialkey', function(f, e){ if(e.getKey() == e.ENTER){ this.onTrigger2Click(); } }, this); }, validationEvent:false, validateOnBlur:false, trigger1Class:'x-form-clear-trigger', trigger2Class:'x-form-search-trigger', hideTrigger1:true, width:180, hasSearch : false, paramName : 'query', onTrigger1Click : function(){ //if(this.hasSearch){ this.el.dom.value = ''; this.triggers[0].hide(); this.hasSearch = false; //} }, onTrigger2Click : function(){ var v = this.getRawValue(); if(v.length < 1){ this.onTrigger1Click(); return; } this.hasSearch = true; this.triggers[0].show(); } }); Ext.reg('cleartriggerfield',Ext.app.clearTriggerField);