1. #1
    Sencha Premium Member
    Join Date
    Apr 2009
    Posts
    162
    Answers
    5
    Vote Rating
    5
    jhoweaa is on a distinguished road

      0  

    Default Answered: Silly question regarding callParent

    Answered: Silly question regarding callParent


    I wanted to experiment with the buildQuery method of Ext.ux.grid.FiltersFeature so I coded up this block of code when I defined the feature to be applied to my grid:

    Inside of my grids 'initComponent method':
    Code:
    ...
    this.features = [
       {
          ftype: 'filters',
          buildQuery: function(filters) {
             console.log('build filter query');
             this.callParent(arguments);
          }
       }
    ];
    ...
    I was surprised when I ran the code to get an exception on the 'this.callParent(arguments)' line for a

    Code:
    Uncaught Error: this.callParent() was called but there's no such method (onBeforeLoad) found in the parent class (Ext.grid.feature.Feature)
    I thought it was odd even though I was in the buildQuery method, the callParent was working inside of the on BeforeLoad. I could see from the walkback that I was in fact in side of the onBeforeLoad method which had made a call to the buildQuery method, but why did callParent execute in the context of onBeforeLoad instead of buildQuery?

    If I really wanted to call the original buildQuery method of Ext.ux.grid.FiltersFeature, what would be the way to do it? Is the only way to create an explicit subclass of Ext.ux.grid.FiltersFeature instead of trying to use this literal object approach?

    Update:

    Here's another thing I don't understand. When I debug the creation of the filter query, I see that my version of 'buildQuery' is executed and then the default version of 'buildQuery' is executed' It seems that my buildQuery isn't really overriding anything. The buildQuery method is executed in the FilterFeatures 'onBeforeLoad' handler which seems to be getting called twice, once with my change and once with the default configuration. Don't really understand why.

    Thanks.

    Jim

  2. Not sure about the specifics of this case but in general...

    You cannot use callParent with an 'inline override'. It can only be used for a proper subclass declared with Ext.define.

    There is one exception. For components you can use xhooks to do an 'inline override'. Do a forum search for xhooks if you want to know more about that, but it isn't relevant to a grid feature.

    However, there's nothing to stop you from overriding a method like this if you don't mind calling the superclass method directly rather than using callParent. Something like:

    Code:
    Ext.ux.grid.FiltersFeature.prototype.buildQuery.apply(this, arguments);

  3. #2
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,501
    Answers
    527
    Vote Rating
    286
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    Not sure about the specifics of this case but in general...

    You cannot use callParent with an 'inline override'. It can only be used for a proper subclass declared with Ext.define.

    There is one exception. For components you can use xhooks to do an 'inline override'. Do a forum search for xhooks if you want to know more about that, but it isn't relevant to a grid feature.

    However, there's nothing to stop you from overriding a method like this if you don't mind calling the superclass method directly rather than using callParent. Something like:

    Code:
    Ext.ux.grid.FiltersFeature.prototype.buildQuery.apply(this, arguments);

  4. #3
    Sencha Premium Member
    Join Date
    Apr 2009
    Posts
    162
    Answers
    5
    Vote Rating
    5
    jhoweaa is on a distinguished road

      0  

    Default


    Thanks for the information. I suspected that I couldn't using 'callParent' in an inline definition but I thought I would give it a try. Your suggestion on how to call the parent class from an inline definition makes sense.

    Thanks again.

    Jim

Thread Participants: 1

Tags for this Thread