Search code examples
extjsextjs4listener

Use different events for same selector in EXTJS


On a grid I need to listen on itemclick and itemkeydown actions, but when I add both of them in my controller then none of them are fired. What is the problem in this code?

How can I listen to keypress event on grid's combobox editor?

http://jsfiddle.net/WRXcw/3/

        'definitiontypeform dtpropertylist': {
            itemclick: this.doSelectPropertyGrid
        },
        'definitiontypeform dtpropertylist': {
            itemkeydown: this.doAddInitial
        },

Solution

  • Try the following

    'definitiontypeform dtpropertylist': {
        itemclick: this.doSelectPropertyGrid,
        itemkeydown: this.doAddInitial
    },
    

    You can add multiple events you want to listen to in the same selector.

    In your code, you add the same key twice to the control object 'definitiontypeform dtpropertylist' which results in unwanted behavior.


    For your Problem in the fiddle

    I can't listen to the keypress here. I have a jsfiddle example for that. how can I listen to keyboard on combobox editor in a grid?

    Add a listener to the editor config for the events you are interested in e.g.

    listeners: {
        keydown: function(){
            // your code ...
        }
    }
    

    And do not forget to enable the Keyevents for the combobox.

    enableKeyEvents: true
    

    The full code should be

    editor: {
            ...
            enableKeyEvents: true,
            listeners: {
                keydown: function(){
                    // your code ...
                }
            }
        },