0
votes

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?

1
Why are you accessing the record from the store? The second argument to the event handler is the record associated with the item clicked. Is there some reason you need to access the record by index instead?Eric
also be careful defining record variable that will mask record variable in the argument list.dbrin

1 Answers

0
votes

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.