View Full Version : How to copy a grid cell value on right mouse click

13 Mar 2013, 8:59 AM
I have added a grid control on a form.
I have added a context menu to that grid.
On the context menu, I have an option to copy a cell text.
In the grid panel, i have added cell selection model.
i was trying to achieve by using action 'beforeitemcontextmenu'

How can i get the value of the selected cell upon right clicking on the grid panel?

can you please someone suggest me how to do it?

13 Mar 2013, 9:29 AM
See if the example below helps. The grid's view has cellclick (dblclick, contextmenu, etc.) events (in 4.2 the events are accessible on the gridpanel component itself, but in 4.1.x just add the listeners to the grid view like in the below example. The cellclick events can be used to get the view, the record for the row clicked, and the cell/column index - all which come in handy when retrieving the value of a cell.

Ext.create('Ext.data.Store', {
fields:['name', 'email', 'phone'],
{ '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,
renderTo: Ext.getBody()
, viewConfig: {
listeners: {
cellcontextmenu: function (view, td, colIndex, record, tr, rowIndex, e) {
Ext.Msg.alert('Text', record.get(view.ownerCt.columns[colIndex].dataIndex));