[CLOSED] FilterHeader and Enter key event

  1. #1

    [CLOSED] FilterHeader and Enter key event

    Hi,

    Is it possible to add Enter key handler for FilterHeader ?

    My scenario:

    AutoReload is disabled. User type filter criteria into one of the filter header text boxes. User can go to another column and type another filter criteria. When user press enter while filter header text box is focused then event is fired. The event will be calling store.load().

    Thank you,
    Last edited by Daniil; Jan 19, 2015 at 3:18 PM. Reason: [CLOSED]
  2. #2
    You can bind the enter key on the fields, can't you?..

    Look at this example: BorderLayout Regions Toggle

    I believe you can join it with the logic of the code:
        <ext:TextField runat="server">
            <ext:KeyMap runat="server">
                <Binding>
                    <ext:KeyBinding>
                        <Keys>
                            <ext:Key Code="ENTER"></ext:Key>
                        </Keys>
                    </ext:KeyBinding>
                </Binding>
            </ext:KeyMap>
        </ext:TextField>
    To bind the enter key to your will. :)
  3. #3
    Hi @matt,

    You might find it useful to override the default behavior:

    Ext.net.FilterHeader.override({
        initField: function (field, column) {
            this.callParent(arguments);
    
            if (field && (!field.isXType("displayfield") || field.filterFn)) {
                this.applyReloadOnEnter(field);
            }
        },
    
        applyReloadOnEnter: function (field) {
            this.autoReload = false;
            field.enableKeyEvents = true;
            field.initEvents();
            field.on('keyup', function (item, e) {
                if (e.getCharCode() == Ext.EventObject.ENTER) {
                    this.applyFilter();
                }
            }, this);
        }
    });
    Last edited by hogaf; Jan 19, 2015 at 9:03 AM.
  4. #4
    Thank you for both solutions. I like the overriding.

    I have got funny behavior... and trying to figure out what is wrong. It might be problem with my implementation only, but has anyone seen that message:

    Requested value 'auto' was not found.

    I am receiving that (ajax) exception when first time press enter (which after overriding calls applyFilter()).
  5. #5
    @matt,

    It seems capturing the field's value is buffered (500 ms is the default value) and it is called upon field change event. So if we apply the onFieldChange body at the time of calling applyFilter that would do the trick.

    Ext.net.FilterHeader.override({
        initField: function (field, column) {
            this.callParent(arguments);
    
            if (field && (!field.isXType("displayfield") || field.filterFn)) {
                this.applyReloadOnEnter(field);
            }
        },
    
        applyReloadOnEnter: function (field) {
            this.autoReload = false;
            field.enableKeyEvents = true;
            field.initEvents();
            field.on('keyup', function (item, e) {
                if (e.getCharCode() == Ext.EventObject.ENTER) {
                    if (this.isSmartFilterValid(item)) {
                        this.runFiltering();
                    }
                    this.applyFilter();
                }
            }, this);
        }
    });
    Last edited by hogaf; Jan 19, 2015 at 10:21 AM.
  6. #6
    Works like a charm now! Thank you.

    One more question. What is the best practice to override Ext.net.FilterHeader ?

    When exactly?
    It is not available straight away.

    I had to do it when my view was loaded. Worked fine until I have noticed that overriding it every time my view was loaded, then listeners were added every time. (after few loads and unloads the event was fired few times ... )

    I have worked around the problem by adding my flag to Ext.net.FilterHeader, but I am sure that is not good solution.

    if (!Ext.net.FilterHeader.wasOverriden) {
    Ext.net.FilterHeader.wasOverriden = true
    
    Ext.net.FilterHeader.override({ ... });
    }
  7. #7
    Since the target is a class declared using Ext.define, then the override method of that class is called upon Ext.override So it's better to not directly use of override method which is deprecated As of Extjs 4.1. It's better to use Ext.define instead:

    You can find more about it in the following link:
    http://docs.sencha.com/extjs/4.1.3/#!/api/Ext
    (Look at the override method)

    Also as you may know there are a couple of ways to modify the default behavior in Extjs like extending, Overriding per instance and on prototype.
    I'd suggest you to take a look at them.

    Ext.define('Override.net.FilterHeader', {
        override: 'Ext.net.FilterHeader',
        initField: function (field, column) {
           ...
        }
    });
  8. #8

    Thread closed

    I choose "Ext.define" :) Works perfectly !

    Thank you,

Similar Threads

  1. [CLOSED] how to fire enter event when click in the textfield?
    By hdsoso in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: May 26, 2014, 5:48 AM
  2. Replies: 4
    Last Post: May 23, 2012, 1:38 PM
  3. [CLOSED] Make enter key activate button click direct event
    By Pablo_Azevedo in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Sep 15, 2010, 6:02 PM
  4. Replies: 1
    Last Post: Jan 27, 2010, 11:21 AM
  5. Stop Enter event on grid update
    By BrunoC in forum 1.x Help
    Replies: 0
    Last Post: Apr 23, 2009, 11:25 AM

Tags for this Thread

Posting Permissions