PDA

View Full Version : grid keypress propagates?



pex
28 Jun 2007, 9:41 AM
Hello,

I want to listen to a keypress event on the grid, eg - when someone has a row selected and clicks on a key, it should fire.

I use this code:


this.on('keypress', function(e){console.log('test')});


It fires correctly when you press a key in the grid, however it also fires when you are in the paging toolbar and enter a different page nr for example. The same applies for the 'header' toolbar I have in this grid. How do I make it so it only fires when a key is pressed in the actual datagrid, and nots its header/footer toolbar?

pex
30 Jun 2007, 12:04 AM
Does anyone have any ideas on this?

Animal
30 Jun 2007, 12:48 AM
This kind of question comes up over and over agaoin. People should learn to use Element.findParent: http://extjs.com/deploy/ext-1.1-beta2/docs/output/Ext.Element.html#findParent

Or http://extjs.com/deploy/ext-1.1-beta2/docs/output/Ext.EventObject.html#getTarget

See if the click event was targeted at an element that is inside the grid's body:



this.on('keypress', function(e) {
if (e.getTarget("div.x-grid-body", myGridContainerElement)) {
console.log('test');
}
});


Where myGridContainerElement is an Element that contains the grid. Eg, the GridPanel's element. Just to stop it iterating up too far.