Search code examples
extjsextjs3

Extjs Cloning a panel


panel({}) and all its contents like grid, form and want to render that exact clone to another panel is there a way to do it..is it possible to do it with panel.getEl() or is there any other way...please help


Solution

  • I must admit that the old answer was not entirely correct. Cloning of Componments is available since ExtJS2 and can be done via cloneConfig(overrides) which is a instance-method.

    This will return a clone of the current instance with the applied overrides (if set). A clean clone will require you to use correct configurations, meaning no instances are created within the config. Here are some information bout this For more details read the Sencha guides


    Old answer (only valid if the components to clone configs contains instances instead of plain configurations)

    No, there is no buildin way to do this. And you should not try it. Consider to wrap the panel in a function that returns a instance of it (a simple sort of factory).

    Edit

    Something like this:

    Factory.Panel = function (config) {
        var defaults = {
            labelWidth: 80,
            labelAlign: 'left',
            layout: 'form',
            width: 720,
            autoHeight: true,
            header: false,
            bodyStyle: 'padding:10px 15px;'
        };
        var cfg = Ext.apply({}, config, defaults);
        var cmp = new Panel(cfg);
        return cmp;
    }
    

    You can add as much function params as you like. This would be a clean way to do it. You just can clone simple object like a record. Note that Factory is a Namespace!