PDA

View Full Version : I want to get the selected cell's value by right click , How should I do?



firstblood
3 May 2013, 4:22 AM
Sorry I have a problem need to bother your

I used extjs 4.1.1a

this is my code as follows



Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['name', 'email', 'phone'],
data:{'items':[
{ 'name': 'Lisa', "email":"lisa@simpsons.com", "phone":"555-111-1224" },
{ 'name': 'Bart', "email":"bart@simpsons.com", "phone":"555-222-1234" },
{ 'name': 'Homer', "email":"home@simpsons.com", "phone":"555-222-1244" },
{ 'name': 'Marge', "email":"marge@simpsons.com", "phone":"555-222-1254" }
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});

Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{ text: 'Name', dataIndex: 'name' },
{ text: 'Email', dataIndex: 'email', flex: 1 },
{ text: 'Phone', dataIndex: 'phone' }
],
height: 200,
width: 400,
selModel: {
xtype: "cellmodel",
listeners: {
select: function(cell, record, row, column, eOpts) {
//I want to get the selected cell's value by right click, How should I do?
//but the column parameter is an object
//this is a bug?
alert(column);
}
}
},
renderTo: Ext.getBody()
});

slemmon
6 May 2013, 9:38 AM
If memory serves cellcontextmenu was an event raised in 4.1.1 against the grid view, but wasn't documented (in 4.2.x you can listen to cellcontextmenu right from the grid itself).

Try:


viewConfig: {
listeners: {
cellcontextmenu: function (view, td, cellIndex, record, tr, rowIndex, e, eOpts) {
e.stopEvent();
var dataIndex = view.ownerCt.down('headercontainer').items.getAt(cellIndex).dataIndex;
console.log(record.get(dataIndex));
}
}
}

firstblood
6 May 2013, 9:35 PM
If memory serves cellcontextmenu was an event raised in 4.1.1 against the grid view, but wasn't documented (in 4.2.x you can listen to cellcontextmenu right from the grid itself).

Try:


viewConfig: {
listeners: {
cellcontextmenu: function (view, td, cellIndex, record, tr, rowIndex, e, eOpts) {
e.stopEvent();
var dataIndex = view.ownerCt.down('headercontainer').items.getAt(cellIndex).dataIndex;
console.log(record.get(dataIndex));
}
}
}


Thank you very much this event just to solve my problem