/**1.
2. * 下拉ComboBoxGrid
3. *
4. * @xtype 'combogrid'
5. */
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--',
assertValue: function () {
this.el.dom.value = this.str==null?"":this.str;
},
/**
* ----------------------------------
* 单击GRID事件
* ----------------------------------
*/
gridClk: function (grid, rowIndex, e) {
this.str="";
for(var i=0;i<grid.getStore().data.items.length;i++)
if ((grid.getStore().data.items[i].data.start!=null && grid.getStore().data.items[i].data.start!="") || (grid.getStore().data.items[i].data.end!=null && grid.getStore().data.items[i].data.end!="")) {
this.str+=grid.getStore().data.items[i].data[this.displayField]+",";
}
this.str=this.str.substring(0,this.str.length-1);
this.setRawValue(this.str);
// this.setValue(grid.getStore().getAt(rowIndex).data[this.valueField]);
// this.setRawValue(grid.getStore().getAt(rowIndex).data[this.displayField]);
// this.setValue(grid.getStore().getAt(rowIndex).data[this.valueField]);
// this.setValue(grid.getRecord(rowIndex).data[this.valueField]);
// this.collapse();
this.fireEvent('gridselected', grid.getStore().getAt(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();
//this.grid.on('rowclick', this.gridClk, this);
}
//single : true
},
'render': {
fn: function () {
}
},
'beforedestroy': {
fn: function (cmp) {
this.purgeListeners();
this.grid.purgeListeners();
}
},
'collapse': {
fn: function (cmp) {
/**
* 防止当store的记录为0时不出现下拉的状况
*/
//debugger
if (this.grid.store.getCount() == 0) {
this.store.add(new Ext.data.Record([{}]));
}
this.grid.stopEditing();
this.gridClk(this.grid);
//this.spuperclass.collapse.call(cmp);
}
}
}
});
/**
* ---------------------------------
* register:'combotree'
* ---------------------------------
*/
Ext.reg('combogrid', ComboBoxGrid);