您的位置:首页 > Web前端 > JavaScript

ExtJS4获取控件展示的信息---获取grid选中项信息

2014-06-18 12:38 399 查看
一、表格grid获取选中行的数据信息:

添加listensers监听器,监听函数可以获取表格信息:

1.选中一行的时候:

selectionchange: function(model, records) {
if (records[0]) {
alert(records[0].data.company);//alert出选中行的company字段内容
this.up('form').getForm().loadRecord(records[0]);//将选中行的内容载入到form表单
}
}


2.在双击的时候:

itemdblclick:function(view, record, items, index, e){
// this.up('form').getForm().loadRecord(record);
alert(record.data.ID_CARD_NUMBER);//record为当前双击的行,alert出ID_CARD_NUMBER字段内容
}

表格中添加一个列,点击时获取行的信息或者执行其他相关当前行的操作:

{
header : '维挽',
xtype : 'actioncolumn',
width : 50,
sortable : false,
items : [{
icon : 'image/icons/delete.gif',
tooltip : '删除已经维系挽留的用户',
handler : function(grid, rowIndex, colIndex) {
Ext.Ajax.request({
url : 'deleteIsHold?name='+ store.getAt(rowIndex).data
4000
.ACCOUNT_USER,
success : function(response, options) {store.removeAt(rowIndex);},
failure : function(response, options) {Ext.Msg.alert('成功',Ext.decode(response.responseText).msg);}
});
}
}]
}


在某个button按钮获取其他情况下获取选中的行:

handler: function(btn, pressed)
{
var row=Ext.getCmp("id_journal_grid").getSelectionModel().getSelections();
//选择行的个数 ,但是本人ExtJS4上面测试出现错误,提示getSelections()不是函数,
if(row.length==0)
{
Ext.Msg.alert("提示信息","请您至少选择一个!");
}
else if(row.length>1){
Ext.Msg.alert("提示信息","对不起只能选择一个!");
}else if(row.length==1)
{
EditJournalInfo(row[0]);//传行一行记录直接加载 编辑角色信息
}
},//上面的方式估计是ExtJS以前的版本?


可以使用这种方法实现:                    

var row=Ext.getCmp("gridpanel").getSelectionModel().getLastSelected();//选择行的个数
         可以这样取值:                          
alert(row.get('ID_CARD_NUMBER'));


也可以这样子取值:

alert(row.data.ID_CARD_NUMBER);


通过getLastSelected()方法获取该行Model格式的数据,然后get需要的值。

二、在其他地方(比如某个button事件)获取某个控件选中的值或者数据

1.radiogroup中获取选中值: 

{//某个地方定义的一个radiogroup
xtype : 'radiogroup',
id:'group2',
fieldLabel : '?????',
labelWidth:200,
defaultType : 'radiofield',
defaults : {
flex : 1
},
layout : 'hbox',
items : [{
boxLabel : '是',
name : 'isNew',
inputValue : 'yes',
id : 'radio3'
}, {
boxLabel : '否',
name : 'isNew',
inputValue : 'no',
id : 'radio4',
checked:true,
margin : '0 0 0 90'
}]
}


在某个地方,可以这样获取选中的radio元素值:

var radio2 = Ext.getCmp('group2').getChecked()[0].boxLabel;


2.获取日期控件的日期值:

Ext.getCmp('month').getValue();


如果需要对获取的日期格式化处理,则可以:

var mytime = Ext.util.Format.date(Ext.getCmp('month').getValue(), 'Y-m');
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: