PDA

View Full Version : Partial extend configuration



KajaSheen
23 Apr 2013, 4:54 AM
Another question about configuration.

I have a specialized Grid component, which has all the columns etc. for a specific model and also a viewConfig. Currently I use this grid in different places. No the necessity arises that I change part of the viewConfig configuration in some places.



Ext.define('Ext.ux.grid.MyGridPanel', {
extend: 'Ext.grid.Panel',
viewConfig: {
listeners: {
itemadd: function() {}
},
plugins: [{ptype: "gridviewdragdrop"}]
},
alias: 'widget.mygridpanel'
});

Ext.widget('mygridpanel', {
viewConfig: {
plugins: [{ptype: "differentplugin"}]
}
});



Is it possible to retain the original configuration for the listeners and only overwrite the plugins configuration?

This is also a core problem for me when i.e. defining my App Viewport and wanting to have only nested parts exchanged dynamically across different pages.

Arg0n
23 Apr 2013, 8:07 AM
Yes it is =)

You would need to write your own constructor for it:



Ext.define('Ext.ux.grid.MyGridPanel', {
extend: 'Ext.grid.Panel',
viewConfig: {
listeners: {
itemadd: function() {}
},
plugins: [{ptype: "gridviewdragdrop"}]
},
alias: 'widget.mygridpanel',

constructor: function(config)
{
Ext.apply(this.viewConfig.plugins, config.viewConfig.plugins);

this.callParent();
}
});

slemmon
24 Apr 2013, 3:04 PM
You might look at this thread. It's not exactly what you're asking but not too far off:
http://www.sencha.com/forum/showthread.php?262096

KajaSheen
25 Apr 2013, 5:09 AM
Thanks for the answers. That is also a strong argument to always use initComponent to set default values for different extended components. But unfortunatly that overcomplicates my code right now. But I will keep that in mind for the future.