PDA

View Full Version : Extending Myself and Ext



zombeerose
3 Apr 2008, 10:05 AM
I would like to know if there is a better way to implement what I have attempted.

I am extending several Ext components (Panel, Grid, etc) that are utilized in my application in order to centralize common functionality. For example, I want all of my grids to be framed and have the same loading message. I also want all my panels to be framed so I have the same property in that config.



MyGrid = Ext.extend(Ext.grid.GridPanel, {
...
frame: true,
loadMask: { msg: 'My custom loading message common for all components' }
...
});
Ext.reg('mygrid', MyGrid);

MyPanel = Ext.extend(Ext.Panel, {
...
frame: true
});
Ext.reg('mypanel', MyPanel);


Since the Ext.grid.GridPanel originally extends Ext.Panel, is there some way that I could extend MyGrid from MyPanel but still get the extra code that an Ext.grid.GridPanel would? Hopefully that made sense.

Thanks in advance.

dj
3 Apr 2008, 10:24 AM
Ext's way of class inheritance cannot handle mutliple-inheritance (as C++ can for example) so you cannot extend your MyGrid from your MyPanel.

There are ways around that (e.g. see this post (http://extjs.com/forum/showthread.php?p=31044#post31044) where i inject a class into another one).

I would probaply do pre-configuration like this


MyGrid = Ext.extend(Ext.grid.GridPanel, {});
Ext.reg('mygrid', MyGrid);
MyPanel = Ext.extend(Ext.Panel, {});
Ext.reg('mypanel', MyPanel);
var defaultconfig = {
...
frame: true,
loadMask: { msg: 'My custom loading message common for all components' }
...
};
Ext.override(MyGrid, defaultconfig);
Ext.override(MyPanel, defaultconfig);


or if you really only use your pre-configred Grids and Panels you could skip the sub-classing:


var defaultconfig = {
...
frame: true,
loadMask: { msg: 'My custom loading message common for all components' }
...
};
Ext.override(Ext.grid.GridPanel, defaultconfig);
Ext.override(Ext.Panel, defaultconfig);


with that code all grids and panels would be magically pre-configured.

zombeerose
4 Apr 2008, 7:55 AM
Thank you dj. That will work :)