extjs editGrid 的键盘监听事件

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 方法,此方法可用于监听键盘事件。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值