Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extjs 4 grid fireevent itemclick

Tags:

extjs4

How do you make a fireEvent itemclick after the store loads.

I have this but it doesn't work:

pcfstore.on('load', function(){
   //auto select first row;
   Ext.getCmp('pcf_grid').getSelectionModel().select(0); // this works

   //fire itemclick event
  var grid= Ext.getCmp('pcf_grid');
  grid.fireEvent('itemclick', grid, 0); //this doesnt work

}); 

Here is my itemclick event in grid view:

viewConfig: {
    listeners: {
    itemclick: function(dv, record, item, index, e) {
           alert(record.data.code);
       }
    }
}

Basically when the grid loads, it should fire the alert window of the selected first row of the grid.

like image 355
Carlo Avatar asked Dec 27 '22 16:12

Carlo


1 Answers

itemclick is event of View but not of Grid. Try to use:

grid.getview().fireEvent('itemclick', grid, 0);

And by the way why not use selectionchange instead.

UPDATE

If you have both itemcontextmenu and selectionchange handlers it can be a little bit confusing. In this case I recommend back to square one and use itemclick event.

But your code need to have some modifications:

  1. Assign itemclick event to grid, NOT to it's view.
  2. When firing itemclick pass actual record, NOT an index

like this:

grid.getSelectionModel().select(0);
grid.fireEvent('itemclick', grid, grid.getSelectionModel().getLastSelected());

And here is fiddle to demonstrate what I'm talking about.

like image 110
Molecular Man Avatar answered Mar 16 '23 22:03

Molecular Man