1. #1
    Sencha User
    Join Date
    Mar 2010
    Posts
    93
    Vote Rating
    0
    ExtKD is on a distinguished road

      0  

    Default [Solved] Add plugin dynamically during initComponent of parent?

    [Solved] Add plugin dynamically during initComponent of parent?


    n/a

  2. #2
    Ext User tonedeaf's Avatar
    Join Date
    Dec 2007
    Posts
    137
    Vote Rating
    1
    tonedeaf is on a distinguished road

      0  

    Default


    For dynamically adding components, ExtJS has a mapping table by component xtype. Component xtype is registered by Ext.reg()

    Similarily, plugins can be registered as a ptype by Ext.preg() and then they can be dynamically added to the plugins array as a sting.
    ExtJS automatically creates a new instance when it parses your plugins array and finds a registered ptype. Eg:

    Code:
    ...
    ...
    Ext.preg('pagesizer', Ext.ux.grid.PageSizer);
    
    Ext.ux.myGrid = Ext.extend(Ext.grid.GridPanel, {
        ...
        ...
        ...
        initComponent: function() {
            this.bbar = new Ext.PagingToolbar({
                store: this.store,
                displayInfo: true,
                displayMsg: 'Displaying records {0} - {1} of {2}',
                emptyMsg: 'No records to display',
                pageSize: 50,
                plugins: ['pagesizer']
            });
            ...
            ...
            Ext.ux.myGrid.superclass.initComponent.apply(this, arguments);
        }
    });

  3. #3
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,508
    Vote Rating
    58
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      -3  

    Default


    Doesn't the documentation tell you how to do this?

    Quote Originally Posted by TFM
    An object or array of objects that will provide custom functionality for this component. The only requirement for a valid plugin is that it contain an init method that accepts a reference of type Ext.Component. When a component is created, if any plugins are available, the component will call the init method on each plugin, passing a reference to itself. Each plugin can then call methods or respond to events on the component as needed to provide its functionality.

  4. #4
    Sencha User steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,664
    Vote Rating
    7
    steffenk has a spectacular aura about steffenk has a spectacular aura about steffenk has a spectacular aura about

      0  

    Default


    have a look to my azfilter - it adds a toolbar to a grid. maybe you find what you're looking for
    http://www.extjs.com/forum/showthread.php?t=96146
    vg Steffen
    --------------------------------------
    Release Manager of TYPO3 4.5

  5. #5
    Sencha User steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,664
    Vote Rating
    7
    steffenk has a spectacular aura about steffenk has a spectacular aura about steffenk has a spectacular aura about

      0  

    Default


    why? Don't see the reason. You could init it and activate on runtime.

    Please describe precise what you try to do
    vg Steffen
    --------------------------------------
    Release Manager of TYPO3 4.5

  6. #6
    Sencha User steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,664
    Vote Rating
    7
    steffenk has a spectacular aura about steffenk has a spectacular aura about steffenk has a spectacular aura about

      0  

    Default


    this.plugins.push('whatever') ? But this should happen before call to parent.
    vg Steffen
    --------------------------------------
    Release Manager of TYPO3 4.5

  7. #7
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,508
    Vote Rating
    58
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      -4  

    Default


    I posted how to. You just need to read.

  8. #8
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,508
    Vote Rating
    58
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      -2  

    Default


    OK, how does a plugin get to know about its client Component? What "declares" the Component to the plugin?

  9. #9
    Sencha User steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,664
    Vote Rating
    7
    steffenk has a spectacular aura about steffenk has a spectacular aura about steffenk has a spectacular aura about

      0  

    Default


    simple:
    Code:
    if (ptbar.plugins) {
       ptbar.plugins.push(psplugin);
    } else {
       ptbar.plugins = [psplugin];
    }
    vg Steffen
    --------------------------------------
    Release Manager of TYPO3 4.5

  10. #10
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,508
    Vote Rating
    58
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      -1  

    Default


    Sigh...

    Plugins initialize themselves when they have their init method called passing the host Component.

    Code:
    psplugin.init(ptbar);