1
votes

I'm working on extjs4. I have a grid panel. on selecting a row of the grid panel, I create a simple window. I would like to close it when the user hits ESC. If the user clicks anything in the window and then clicks ESC, the window is closed. But if the user didn't touched the window yet, ESC would not close the window. Any idea how to do that?

var win = Ext.create('Ext.window.Window', {
                    title: 'Details',
                    width: 400,
                        layout: 'fit',
                        iconCls: 'details-icon',
                        items: simple
                    }).show();
1
The problem is in the snippet that does the closing. Post that please.Amol Katdare
I don't have any snippet that does the closing. I think the problem is that the focus is not in this window until I click on it (this is why ESC doesn't close). I thought that when you create Window and show in this way the focus automatically moves to the window, but apparently needs some additional settings.nnahum
I think if you add modal:true to your window config, it will work as you expect.Amol Katdare
interesting, I tried the modal:true, it greys out the rest of the screen as expected but still don't close the window when pressing ESC. (like before, only if first I click inside the window with the mouse, then ESC close the window).nnahum

1 Answers

3
votes

maybe it's no foucus at win.

or try to use this:

listen to window show event, and add a KeyMap to document:

 var map = new Ext.util.KeyMap(Ext.getBody(), [{
    key: Ext.EventObject.ESC,
    defaultEventAction: 'preventDefault',
    scope: this,
    fn: function(){win.close()}
 }]);