答案 0 :(得分:0)
您可以使用selModel获得选定的记录,如下所示:
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.define('User', {
extend: 'Ext.data.Model',
fields: ['name', 'email', 'phone']
});
var userStore = Ext.create('Ext.data.Store', {
model: 'User',
data: [{
name: 'Lisa',
email: 'lisa@simpsons.com',
phone: '555-111-1224'
}, {
name: 'Bart',
email: 'bart@simpsons.com',
phone: '555-222-1234'
}, {
name: 'Homer',
email: 'homer@simpsons.com',
phone: '555-222-1244'
}, {
name: 'Marge',
email: 'marge@simpsons.com',
phone: '555-222-1254'
}, {
name: 'Shreya',
email: 'marge@simpsons.com',
phone: '555-222-1254'
}
]
});
Ext.create({
xtype: 'panel',
title: 'Grid Panel',
renderTo: Ext.getBody(),
items: [{
xtype: 'grid',
id: 'mygrid',
store: userStore,
storeId: 'mystore',
width: 400,
height: 200,
selModel: {
selType: 'checkboxmodel',
checkOnly: true,
injectCheckbox: 0,
showHeaderCheckbox: false,
listeners: {
}
},
title: 'Application Users',
columns: [{
text: 'Name',
width: 100,
sortable: false,
hideable: false,
dataIndex: 'name'
}, {
text: 'Email Address',
width: 150,
dataIndex: 'email',
hidden: true
}, {
text: 'Phone Number',
flex: 1,
dataIndex: 'phone'
}]
},{
xtype: 'panel',
items: [{
xtype: 'button',
text: 'get selected record',
handler: function() {
var myGrid = Ext.getCmp('mygrid');
var selections = myGrid.getSelections();
console.log(selections);
}
}]
}]
})
//Ext.Msg.alert('Fiddle', 'Welcome to Sencha Fiddle!');
}
});
链接至工作小提琴: https://fiddle.sencha.com/#view/editor&fiddle/2l15