var test_grid = Ext.create('Ext.grid.Panel',{
id: 'test_grid_id',
columns: [
{text: "MsgId", dataIndex: 'MsgId',hidden: true},
{text: "Read", dataIndex: 'Read',hidden: true},
{text: "Subject", flex: 1, dataIndex: 'Subject',renderer: gridformat}
],
listeners: {
selectionchange : function(model, records) {
if (records != 'undefined' && records.length > 0) {
var Subject = records[0].data.Subject; //获取行数据
alert(Subject);
var Read = records[0].data.Read; //获取行数据
if(Read == "true"){
alert("true");
}else{
alert("false");
}
}
}
}
});
上边是行单机事件,如果通过点击某行实现删除等功能,就需要用到
var msgid = test_grid.getSelectionModel().getLastSelected().get('MsgId');
下边放一个Extjs4.2之前版本的获取行数据的办法,可获取多行数据。此例可适用于多行删除。
1. 获取
function get_MsgIds(){
var recs = test_grid.getSelectionModel().getSelections();// 获取选择行(一行或多行)的数据集
var list = [];
if(recs.length != 0){
for(var i = 0 ; i < recs.length ; i++){
var rec = recs[i];// 取得一行
list.push(rec.get('MsgId'))// 取得该行中的某个属性的值
}
}
return list;
}
2. 删除按钮
tbar: [
{text: '删除!',handler: function(){
var list = get_MsgIds();
var num = list.length;
if(num == 0){
Ext.Msg.alert('提示','请选择删除的数据');
}else{
delete(list);
}
}}
]
3. 删除
function delete(list){
var MsgIds = list.join(',');
Ext.Ajax.request({
url: '...',
params: {
FKeyID: MsgIds
},
method: 'POST',
success: function(response,options){
var result = Ext.util.JSON.decode(response.responseText);
},
failure: function(response,options){
}
});
}