EXT的GridPanel与FormPanel交互

联系了下gridpanel 与 formpanel  ,以备以后查看
Ext.onReady(function(){
  var _grid = new Ext.grid.GridPanel({
  id:'viewGrid',
  title:'GridPanel',
  renderTo:Ext.getBody(),
  width:320,
  height:200,
  colModel:new Ext.grid.ColumnModel([{
  header:'姓名'
  },{
  header:'性别'
  },{
  header:'年龄'
  }]),
  store:new Ext.data.JsonStore({
  autoLoad:true,
  url:'<%=path%>/store/Data.jsp',
  fields:['name','sex','age']
  }),
  selModel:new Ext.grid.RowSelectionModel({
  singleSelect:true,
  listeners:{
  'rowselect':function(){
  var _r = Ext.getCmp('viewGrid').getSelectionModel().getSelected();
 
  Ext.getCmp('viewForm').getForm().loadRecord(_r);
  }
  }
  })
  });
 
  var _form = new Ext.form.FormPanel({
  id:'viewForm',
  frame:true,
  renderTo:Ext.getBody(),
  autoShow:true,
  defaultType:'textfield',
  width:320,
  labelWidth:50,
  defaults:{width:200},
  items: [{
  fieldLabel:'姓名',
  name:'name'
  },{
  fieldLabel:'性别',
  name:'sex'
  },{
  fieldLabel:'年龄',
  name:'age'
  }],
  buttons:[{
  text:'修改',
  handler:function(){
if(Ext.getCmp('viewGrid').getSelectionModel().getCount == 0)return;

var _r = Ext.getCmp('viewGrid').getSelectionModel().getSelected();

var _formValues = Ext.getCmp('viewForm').getForm().getValues();

_r.set('name',_formValues['name']);

_r.set('sex',_formValues['sex']);

_r.set('age',_formValues['age']);

_r.commit();
  }
  }]
 
  });
  });

你可能感兴趣的:(ext)