PeriodSetEditGrid = Ext.extend(Ext.grid.Panel, {
_editor : false,
_period : 4,
_auditMoney : null,
constructor : function(_config) {
if (_config == null)
_config = {};
Ext.apply(this, _config);
var onKeypress =function(e) {
var k = e.getKey();
if( (k == e.ENTER)) {
e.stopEvent();
}
};
this['rowEditing'] = Ext.create('Ext.grid.plugin.RowEditing', {
clicksToMoveEditor: 1,
autoCancel: false
});
this["store"] = {
proxy : {
type : 'ajax',
url : "xmgl/period-set-manage.action",
reader : {
type : 'json',
root : 'rows',
totalProperty : "totalCount"
}
},
model : 'PeriodSet',
listeners : {
'load' : {
fn : this.loadHander,
scope : this
}
}
};
this['columns'] = [ new Ext.grid.RowNumberer( {
header : "序号",
width : 38
}), {
text : '状态',
flex : 1,
dataIndex : 'status'
}, {
text : '收款日期',
flex : 1,
xtype : 'datecolumn',
format : 'Y-m-d',
dataIndex : 'payDate',
editor: {
xtype: 'datefield',
format: 'Y-m-d'
}
}, {
text : '比例(%)',
flex : 1,
_grid:this,
dataIndex : 'proportion',
editor: {
xtype: 'numberfield',
minValue : 0,
maxValue : 100,
_grid:this,
listeners : {
'keypress' : {
fn : function(_field,e){
var k = e.getKey();
console.log('ds');
if( (k == e.ENTER)) {
return false;
}
},
scope : this
},
specialkey:function(_field,e){
// console.log('ds');
this._auditMoney = _field._grid._auditMoney;
if (e.getKey()==Ext.EventObject.ENTER){
if(this._auditMoney>0){
_field.ownerCt.form.setValues({'payMoney':(this._auditMoney*_field.value/100).toFixed(2)});
}
}
} ,
'blur' : {
fn : function(_field,_a,_b){
if(this._auditMoney>0){
_field.ownerCt.form.setValues({'payMoney':(this._auditMoney*_field.value/100).toFixed(2)});
}
},
scope : this
},
'focus' : {
fn : function(_field,_a,_b){
if(!this._auditMoney>0){
warningMesg({msg : '请输入合同金额!'});
return;
}
},
scope : this
}
}
}
}, {
text : '收款金额',
flex : 1,
dataIndex : 'payMoney',
renderer : Ext.common.utils.GridPanelUtils.cellMoneySplitRenderer,
editor: {
xtype: 'numberfield',
minValue : 0.0,
_grid:this,
listeners : {
specialkey:function(_field,e){
// console.log('ds');
if (e.getKey()==Ext.EventObject.ENTER){
this._auditMoney = _field._grid._auditMoney;
if(this._auditMoney>0){
_field.ownerCt.form.setValues({'proportion':(newValue/this._auditMoney*100).toFixed(2)});
}
}
} ,
'change' : {
fn : function(_field,newValue, oldValue){
if(newValue>this._auditMoney){
warningMesg({msg : '付款金额不应大于合同金额!'});
console.log(this._auditMoney);
_field.setValue(oldValue);
return;
}
_field.ownerCt.form.setValues({'proportion':(newValue/this._auditMoney*100).toFixed(2)});
},
scope : this
},
'focus' : {
fn : function(_field,_a,_b){
if(!this._auditMoney>0){
warningMesg({msg : '请输入审计金额!'});
return;
}
},
scope : this
}
}
}
}, {
text : '备注',
flex : 2,
dataIndex : 'remark',
editor: {}
} ]
PeriodSetEditGrid.superclass.constructor.call(this, {
height : 230,
plugins: [this.rowEditing],
viewConfig : {
stripeRows : true,
enableTextSelection : true,
getRowClass : function(record) {
if (record.get("status") == '进行中') {
return 'bluecss';
}else if (record.get("status") == '已付款') {
return 'greencss';
}
}
},
tbar : [ {
text : "新增行",
// id : 'BT_PERIODSET_ADD',
handler : this.onAddRow,
scope : this
}, {
text : "删除行",
// id : 'BT_PERIODSET_DEL',
handler : this.onDelRow,
scope : this
}, {
text : "保存",
// id : 'BT_PERIODSET_SAVE',
handler : this.onSaveHandler,
scope : this
} ]
//,
// viewConfig : {
// stripeRows : true,
// enableTextSelection : true
// }
});
// if(!this._editor){
// Ext.getCmp('BT_PERIODSET_ADD').hide();
// Ext.getCmp('BT_PERIODSET_DEL').hide();
// Ext.getCmp('BT_PERIODSET_SAVE').hide();
// }
},
loadHander : function(_load,_datas){
if(this._period> this.store.getCount()){
var _size = this._period -this.store.getCount();
for(var i=0;i<_size;i++)
this.store.insert(this.store.getCount(),new PeriodSet());
}
},
onSearch : function(_guId){
this._proGuId = _guId;
if(_guId>0){
this.store.proxy.extraParams ={proGuId : _guId};
this.store.load();
}
}
});
以上grid 的 比例 在进行编辑的时候添加了 specialkey 方法,此方法可用于监听键盘事件。
extjs editGrid 的键盘监听事件
最新推荐文章于 2022-10-31 17:01:04 发布