var depotStore = new Ext.data.JsonStore({
root:'root',
url:'json/table_batch_json.jsp',
fields:[
{name:"HouseCode"},
{name:"HouseName"},
{name:"GFeedMethd",type:'combo'},
{name:"STDate",type:'date'},
{name:"EDDate",type:'date'},
{name:"EDDate2",type:'date'},
{name:"action"}
],
//pruneModifiedRecords:true, //True表示为,每次Store加载后,清除所有修改过的记录信息;record被移除时也会这样(默认为false)。
autoLoad:true
});
var colM = new Ext.grid.ColumnModel([
{ header:"栋编号",
dataIndex:"HouseCode",
sortable:true,
align:'center',
width:70
},
{ header:"栋名称",
dataIndex:"HouseName",
sortable:true,
align:'center',
width:70
},
{ header:"饲养方法",
dataIndex:"GFeedMethd",
sortable:true,
align:'center',
width:70,
renderer:function(GFeedMethd) {
var idx = methodStore.find("key", GFeedMethd);
return (idx != "-1") ? methodStore.getAt(idx).data.value : '';
},
editor : new Ext.form.ComboBox({
editable : false,
displayField:'value',
valueField:'key',
id:'GFeedMethdeditor',
mode: 'remote',
triggerAction: 'all',
store:methodStore
})
},
{ header:"入舍日期",
dataIndex:"STDate",
sortabel:false,
align:'center',
renderer:Ext.util.Format.dateRenderer('Y-m-d'),
editor:new Ext.form.DateField()
},
{ header:"第一次出栏日期",
dataIndex:"EDDate",
sortabel:false,
align:'center',
renderer:Ext.util.Format.dateRenderer('Y-m-d'),
editor:new Ext.form.DateField()
},
{ header:"第二次出栏日期",
dataIndex:"EDDate2",
sortable:true,
align:'center',
renderer:Ext.util.Format.dateRenderer('Y-m-d'),
editor:new Ext.form.DateField()
},
{ header:"操作",
xtype:"actioncolumn",
align:'center',
width:70,
items:[{
icon:'/resource/images/icon/fam/delete.gif',
handler:function(grid,rowIndex,colIndex){
var select = grid.getStore().getAt(rowIndex);
grid.getStore().remove(select);
}
}]
}
]);
var baseForm = new Ext.form.FormPanel( {
renderTo:'tasktype',
height: 460,
width: 580,
frame : true,
layout:'absolute',
bodyStyle : 'padding:5px 5px;background:white',
waitMsgTarget : true,
defaultType : 'textfield',
items : [{
y:130,
xtype:'combo',
fieldLabel: "类型",
width:130,
name:'Type',
id:'Type',
triggerAction:"all",
store:typeStore,
editable:false,
displayField:"value",
valueField:"key",
mode:"remote",
listeners : {
select : function(combo, record, index) {
if(combo.getValue()=="DC"){
Ext.getCmp("datalist").hide();
paneldata.hide();
Ext.getCmp("TaskDocCode").enable();
Ext.getCmp("TaskDocCode").allowBlank=true;
}else if(combo.getValue()=="SI"||combo.getValue()=="UI"){
Ext.getCmp("datalist").show();
paneldata.show();
if(paneldata.getStore().getCount()<1){
var newRecord = new myrecord({
DataName:'',
Mandatory:'',
action:''
});
paneldata.stopEditing();
paneldata.getStore().insert(0,newRecord);
paneldata.startEditing(0,0);
};
Ext.getCmp("TaskDocCode").disable();
}else if(combo.getValue()=="IN"){
Ext.getCmp("datalist").hide();
paneldata.hide();
Ext.getCmp("TaskDocCode").disable();
}
}
}
},paneldata = new Ext.grid.EditorGridPanel({
x:10,
y:255,
id:'editordepot',
height:120,
width:580,
cm:colM,
columnLines:true,
enableColumnResize:false,
enableColumnMove:false,
store:depotStore,
clicksToEdit:2,
viewConfig: {
markDirty: false
}
})],
tbar:[
{text:'保存',id:'save',iconCls:'save',handler:saveRecord},"-",
{text:'删除',id:'delete',iconCls:'del',handler:deleteRecord}
]
});
baseForm.getForm().load({
url: '/module/pc/sys/base/record_json.jsp?table='+table+'&key='+key+'&id='+id,
success:function(form, action){
var combo = Ext.getCmp("Type");
var uid = combo.getValue();
combo.fireEvent('select',combo,combo.getStore().getById(uid));
},
failure: function(form, action) {
Ext.Msg.alert("Load failed", "失败");
}
});
注解:
1.combo.getStore().getById(uid)只有在store中设置了属性id才能够获取到
2.fireEvent('select',combo,combo.getStore().getById(uid)) 第一个是控件本身,第二个就是record,也就是store中的一条记录。那么,通过store中的id来返回对应的record就需要getById方法