Eldwin Eldwin
Eldwin Eldwin

Reputation: 1094

Get value of clicked cell on grid

I have been trying to get the value of clicked cell on grid.

cellDblClick: function(self, td, cellIndex, record, tr, rowIndex, e, eOpts)

I know I can get the record data, but I need the name of the column to get the value of the data.

record.data["name_of_column"]

What's the approach to get the value of clicked cell on grid? Is it possible to get the column name of clicked cell on grid?

Can anyone shed the light for me?

N.B. I'm using extjs 4.2.1

Upvotes: 6

Views: 18298

Answers (3)

pedro.caicedo.dev
pedro.caicedo.dev

Reputation: 2435

You can use:

cellclick: function( thisGrid, td, cellIndex, record, tr, rowIndex, e, eOpts )
{
    console.log('td/cell value: ', td.innerText);

},

Upvotes: 0

ddragos
ddragos

Reputation: 81

You can use :

onGridpanelCellDblClick: function(tableview, td, cellIndex, record, tr, rowIndex, e, eOpts) {
    var clickedColumnName = record.getFields()[cellIndex-1].getName();
    var clickedCellValue = record.get(clickedColumnName);
}

The cell index starts from 1 so you have to use cellIndex-1 for the array returned by record.getFields().

Upvotes: 0

Dev
Dev

Reputation: 3932

You can use viewConfig of grid with cellclick listener as follows.

 viewConfig : {
    listeners : {
        cellclick : function(view, cell, cellIndex, record,row, rowIndex, e) {

              var clickedDataIndex = view.panel.headerCt.getHeaderAtIndex(cellIndex).dataIndex;
              var clickedColumnName = view.panel.headerCt.getHeaderAtIndex(cellIndex).text;
              var clickedCellValue = record.get(clickedDataIndex);
          }
     }
 }

Upvotes: 15

Related Questions