Search code examples
extjsextjs4

Adding listener to Ext.Grid.panel in EXTJS 4


I am trying to add a listener to a Ext.grid.panel

listeners: {

itemclick:function( grid, record, item, index, event){

alert(index);
var record = grid.getStore().getAt(index);
alert("Edit " + record.get('data'));
alert("Type " + record.get('type'));

}

I suppose to get the index value of the row I clicked. So when I click the row for the first time I get : [object Object] in the alert box with index in it. The second two alerts don't appear at all.

So when I again click the same row. it shows the correct index and then "data" and then " type" in an alert box.

How can I get the right values on the first click only?


Solution

  • When I add your listener to a grid panel of my own, I get the same behavior every time. For example: 4/"Edit undefined"/"Type undefined".

    That you are seeing different behaviors depending on if it is the first time you click an item or not likely has something to do with how the grid is created/rendered.

    The content of the Object passed as "index" to your listener function might give you a clue. If you log it to the console you'll be able to inspect it. (At least that's how Chrome handles logging of objects).

    While this is not a solution to your problem, I hope it helps in your debugging.