MyComboBox = Ext.extend(Ext.form.ComboBox, {
initList : function(){
MyComboBox.superclass.initList.call(this);
if(this.clearable){
var combox = this;
var cls = 'x-combo-list';
this.footer = this.list.createChild({
cls : cls + '-ft'
});
this.spaceR = new Ext.Toolbar({
items : [
'->',
{
iconCls : 'bico_btnqk',
text : '清空',
handler : function(){
combox.setText('','');
combox.collapse();
}
}
],
renderTo : this.footer
});
this.assetHeight += this.footer.getHeight();
}
this.store.load();
},
setText : function(text, value){
this.lastSelectionText = text;
if(this.hiddenField){
this.hiddenField.value = value;
}
Ext.form.ComboBox.superclass.setValue.call(this, text);
this.value = value;
},
getValue : function(){
return typeof this.value != 'undefined' ? this.value : '';
},
getText : function(){
return typeof this.lastSelectionText != 'undefined' ? this.lastSelectionText : '';
},
doQuery : function(q, forceAll){
if(q === undefined || q === null){
q = '';
}
var qe = {
query : q,
forceAll : forceAll,
combo : this,
cancel : false
};
if(this.fireEvent('beforequery',qe) === false || qe.cancel){
return false;
}
q = qe.query;
forceAll = qe.forceAll;
if(forceAll === true || (q.length >= this.minChars)){
if (this.editable === true){
this.store.baseParams[this.queryParam] = q;
this.store.load({
params: this.getParams(q)
});
this.expand();
}else{
if(this.lastQuery !== q){
this.lastQuery = q;
if(this.mode == 'local'){
this.selectedIndex = -1;
if(forceAll){
this.store.clearFilter();
}else{
this.store.filter(this.displayField, q);
}
this.onLoad();
}else{
this.store.baseParams[this.queryParam] = q;
this.store.load({
params: this.getParams(q)
});
this.expand();
}
}else{
this.selectedIndex = -1;
this.onLoad();
}
}
}
},
listeners : {
'beforequery' : function(e){
var combo = e.combo;
if(!e.forceAll){
var input = e.query;
// 检索的正则
var regExp = new RegExp(".*" + input + ".*");
// 执行检索
combo.store.filterBy(function(record,id){
// 得到每个record的项目名称值
var text = record.get(combo.displayField);
return regExp.test(text);
});
combo.expand();
return false;
}
}
}
});
var qMaterielInfoStore = new Ext.data.JsonStore({
url : '../../../dfo/com_web/sys/Common/getMaterielInfo.do',
root : 'ROOT',
totalProperty : 'TOTALCOUNT',
id : 'materielid',
fields : ['materielid','shortname','objecttype'],
sortInfo : {field : 'materielid', direction : 'ASC'},
baseParams : {
'objecttype' : "0",
'dataFields' : escape('materielid,shortname,objecttype')
}
});
var qMaterielInfo = new MyComboBox({
id : 'qMaterielInfo',
name : 'qMaterielInfo',
fieldLabel : '物料名称',
store : qMaterielInfoStore,
valueField : 'materielid',
displayField : 'shortname',
lazyRender : true,
triggerAction : 'all',
anchor : '100%',
editable : true,
clearable : true
});