How to get column name from rowselection in ExtJS grid?

I have an extjs gridpanel setup and I want to be able to do things based on user clicks of text or icons in the grid. For example, filter the grid if the user clicks (or double-clicks) a word in a column, or shows a popup if the user clicks on an icon. I can easily get the row they clicked on and the values ​​by column name from that row, but I don't know which column was clicked.

Alternatively, I could add onClick to the entire grid, and then I could get the individual text from the row / column, but I don't know which row or column index the value belongs to. I could add a CSS class that would tell me the column name, but that seems like a hack.

Is there anything built in that can do this?

+2


source to share


3 answers


"cellclick" event on the grid is the path. The function that listens for this event is executed:

  • ( Grid this, Number rowIndex, Number columnIndex, Ext.EventObject e )

If you want to get the text of the gridCell, the call yourGrid.getView().getCell(rowIndex, colIndex)

will return the DOM element.



If you want a column header, call: yourGrid.getColumnModel()

.getColumnHeader(colIndex)

If you want to find anything else about a specific column, call yourGrid.getColumnModel()

.getColumnAt(colIndex)

+7


source


I think if you are interested in column events then rowselection is the wrong event to study. As Joshua assumed the cellclick event is an event you should look into.

This event can give the dataIndex of the column as specified



var fieldName = grid.getColumnModel().getDataIndex(columnIndex); 

      

+1


source


Please see the edit-grid.html example for rendering and event handling.

0


source







All Articles