mirinda95925
2009-11-19 14:43
浏览 240
已采纳

ExtJS选中记录赋值的问题

/*

  • My test
  • */ MyDesktop.GridWindow1 = Ext.extend(Ext.app.Module, { id:'grid-win1', init : function(){ this.launcher = { text: '我的测试,嘿嘿', iconCls:'icon-grid', handler : this.createWindow, scope: this } },

createWindow : function(){
/*

  • 对生成的表格进行扩展
  • */ var ds = new Ext.data.JsonStore({ remoteSort:true, url:'/newDesktop/fixinfo/getAll', fields:[ 'a','b','c','d','e', 'f','hhh','ggg' ], baseParams:{ limit:10 } }); ds.load({ params:{start:0} }); //end

var thisGrid = new Ext.grid.GridPanel({
border:false,
store:ds,
columns:[
{header:'设备编号',dataIndex:'a',width:100,sortable:true},
{header:'设备名称',dataIndex:'b',width:100},
{header:'型号规格',dataIndex:'c',width:100},
{header:'区域',dataIndex:'d',width:80},
{header:'设备类型',dataIndex:'e',width:100},
{header:'生产国别',dataIndex:'f',width:100},
{header:'生产厂家',dataIndex:'hhh',width:100},
{header:'出厂编号',dataIndex:'ggg',width:100}
],

viewConfig: {
forceFit:true
},
//autoExpandColumn:'company',
bbar:new Ext.PagingToolbar({
store:ds,
pageSize:10,
displayinfo:'true',
displayMsg:'显示第{0}条记录到第{1}条记录,一共{2}条',
emptyMsg:'没有记录'
}),
tbar:[{
text:'增加设备',
tooltip:'点击这里来增加设备',
iconCls:'add',
handler:this.createUser.createDelegate(this)
}, '-', {
text:'修改设备',
tooltip:'选定一条记录后进行修改',
iconCls:'option',
handler:this.EditUser.createDelegate(this)
},'-',{
text:'删除设备',
tooltip:'选定一条设备之后进行删除',
iconCls:'remove'
}]
})

var desktop = this.app.getDesktop();
var win = desktop.getWindow('grid-win1');

if(!win){
win = desktop.createWindow({
id: 'grid-win1',
title:'我的测试',
width:740,
height:480,
iconCls: 'icon-grid',
shim:false,
animCollapse:false,
constrainHeader:true,
layout: 'fit',
items:thisGrid
});
}

win.show();

},
createUser:function(){
this.fixInfoWindow = new FixInfoWindow({
grid:this
});

this.fixInfoWindow.show();
//this.FixInfoWindow.setTitle('新建用户资料');
//this.FixInfoWindow.url = 'user/save'; //此处的url对应着UserController的save()方法
//this.FixInfoWindow.fp.form.reset();
},

EditUser:function(){

var rec =thisGrid.getSelectionModel().getSelected();
alert(rec)

if(rec){

this.fixInfoWindow = new FixInfoWindow({
grid:this
});
this.fixInfoWindow.show();
this.fixInfoWindow.fp.form.loadRecord(rec);
}
else{Ext.Msg.alert("出错了","请选择一条记录操作"); }

}

});

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • xkuff 2009-11-20 09:04
    已采纳

    1.你的代码里好像没有定义Ext.grid.CheckboxSelectionModel
    2.把EditUser函数中的代码改成:
    var grid = Ext.getCmp('grid id');
    if (grid == null) {
    return;
    }
    var sm = grid.getSelectionModel();
    if (sm == null) {
    return;
    }
    var selections = sm.getSelections();
    if (selections == null) {
    return;
    }
    if (selections.length > 0) {
    var record = selections[0];
    if (record == null) {
    return;
    }
    }
    Ext.getCmp('form id').getForm().loadRecord(rec);

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题