扩展combobox的下拉Grid


/**
* 下拉ComboBoxGrid
*
* @xtype 'combogrid'
* @author chengbao_zhu
*/


ComboBoxGrid = Ext.extend(Ext.form.ComboBox, {

gridHeight : 180,
listAlign : 'tr-br',
listWidth : 300,
store : new Ext.data.SimpleStore({
fields : [],
data : [[]]
}),
resizable : false,
// Default
editable : false,
mode : 'local',
triggerAction : 'all',
maxHeight : 500,
selectedClass : '',
onSelect : Ext.emptyFn,
emptyText : '\u8bf7\u9009\u62e9...',


/**
* ----------------------------------
* 单击GRID事件
* ----------------------------------
*/
gridClk : function(grid, rowIndex, e) {

this.setRawValue(grid.getRecord(rowIndex).data[this.displayField]);
this.setValue(grid.getRecord(rowIndex).data[this.valueField]);
this.collapse();

this.fireEvent('gridselected', grid.getRecord(rowIndex));

},

initLayout : function(){
this.grid.autoScroll = true;
this.grid.height = this.gridHeight;
this.grid.containerScroll = false;
this.grid.border=false;

this.listWidth = this.grid.width+3;
},
/**
* Init
*/
initComponent : function() {
ComboBoxGrid.superclass.initComponent.call(this);
this.initLayout();
this.tplId = Ext.id();
// overflow:auto"
this.tpl = '<div id="' + this.tplId + '" style="height:' + this.gridHeight
+ ';overflow:hidden;"></div>';

//Add Event
this.addEvents('gridselected');
},

/**
* ------------------
* Listener
* ------------------
*/
listeners : {
'expand' : {
fn : function() {
if (!this.grid.rendered && this.tplId) {
//this.initComponent();
this.initLayout();

this.grid.render(this.tplId);
this.store = this.grid.store;

this.store.reload();
if(this.store.getCount()==0){
this.store.add(new Ext.data.Record([{}]));
}
//this.grid.store.reload();
this.grid.on('rowclick', this.gridClk, this);
}

this.grid.show();
}
//single : true
},

'render' : {
fn : function() {

}
},
'beforedestroy' : {
fn : function(cmp) {
this.purgeListeners();
this.grid.purgeListeners();
}
},
'collapse' : {
fn : function(cmp) {
/**
* 防止当store的记录为0时不出现下拉的状况
*/
if(this.grid.store.getCount()==0){
this.store.add(new Ext.data.Record([{}]));
}
}
}
}

});

/**
* ---------------------------------
* register:'combotree'
* ---------------------------------
*/
Ext.reg('combogrid', ComboBoxGrid);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值