主要是实现grid的edit事件,查看Ext.data.StoreManager.lookup("gridStore")
找到store之后,查看最后一个recorde是否为空,不为空才新增一行
Ext.onReady(function(){
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget='side';
var store=Ext.create('Ext.data.Store',{
storeId:'gridStore',
autoLoad:true,
fields:['Name','Password','RPassword','Email'],
data:{'items':[
{'Name':'','Password':'','RPassword':'','Email':''},
]},
proxy:{
type:'memory',
reader:{
type:'json',
root:'items'
}
}
});
var gridPanel=Ext.create('Ext.grid.Panel',{
autoScroll:true,
height:110,
store:store,
plugins:[
Ext.create('Ext.grid.plugin.CellEditing',{
clicksToEdit:1
})
],
columns:[
{header:'用户名',dataIndex:'Name',flex:1,
editor:{
xtype:'textfield',
name:'username',
allowBlank:false,
blankText:'用户名不能为空'
}
},
{header:'密码',dataIndex:'Password',flex:1,
editor:{
xtype:'textfield',
name:'password1',
id:'password1',
allowBlank:false,
inputType:'password',
blankText:'密码不能为空'
}
},
{header:'确认密码',dataIndex:'RPassword',flex:1,
editor:{
xtype:'textfield',
name:'password2',
allowBlank:false,
inputType:'password'
}
},
{header:'邮箱',dataIndex:'Email',flex:1,
editor:{
xtype:'textfield',
name:'email',
allowBlank:false,
vtype:'email',
vtypeText:'邮箱格式不正确!'
}
},
],
listeners:{
edit:function(editor,eOptions){
var store=Ext.data.StoreManager.lookup("gridStore");
var lastRecord=store.last();
var temp=lastRecord.get('Name')+lastRecord.get('Password')
+lastRecord.get('RPassword')+lastRecord.get('Email');
temp=Ext.util.Format.trim(temp);
if(temp!=""){
var newRecord={'Name':'','Password':'','RPassword':'','Email':''};
store.add(newRecord);
}
}
}
});