How to create custom ExtJS form field component?

后端 未结 9 544
无人共我
无人共我 2020-12-02 11:34

I want to create custom ExtJS form field components using other ExtJS components in it (e.g. TreePanel). How can I do it most easily?

I\'ve read doc

9条回答
  •  一整个雨季
    2020-12-02 11:53

    Here is an example of a custom panel that extends an Ext Panel. You can extend any component, check the docs for the fields, methods and events you can play with.

    Ext.ns('yournamespace');
    
    yournamespace.MyPanel = function(config) {
        yournamespace.MyPanel.superclass.constructor.call(this, config);
    } 
    
    Ext.extend(yournamespace.MyPanel, Ext.Panel, {
    
        myGlobalVariable : undefined,
    
        constructor : function(config) {
            yournamespace.MyPanel.superclass.constructor.apply(this, config);
        },
    
        initComponent : function() {
            this.comboBox = new Ext.form.ComboBox({
                fieldLabel: "MyCombo",
                store: someStore,
                displayField:'My Label',
                typeAhead: true,
                mode: 'local',
                forceSelection: true,
                triggerAction: 'all',
                emptyText:'',
                selectOnFocus:true,
                tabIndex: 1,
                width: 200
            });
    
            // configure the grid
            Ext.apply(this, {
                listeners: {
                    'activate': function(p) {
                        p.doLayout();
                     },
                     single:true
                },
    
                xtype:"form",
                border: false,
                layout:"absolute",
                labelAlign:"top",
                bodyStyle:"padding: 15px",
                width: 350,
                height: 75,
    
                items:[{
                    xtype:"panel",
                    layout:"form",
                    x:"10",
                    y:"10",
                    labelAlign:"top",
                    border:false,
                    items:[this.comboBox]
                },
                {
                    xtype:"panel",
                    layout:"form",
                    x:"230",
                    y:"26",
                    labelAlign:"top",
                    border:false,
                    items:[{
                        xtype:'button',
                        handler: this.someAction.createDelegate(this),
                        text: 'Some Action'
                    }]
                }]
            }); // eo apply
    
            yournamespace.MyPanel.superclass.initComponent.apply(this, arguments);
    
            this.comboBox.on('select', function(combo, record, index) {
                this.myGlobalVariable = record.get("something");
            }, this);
    
        }, // eo function initComponent
    
        someAction : function() {
            //do something
        },
    
        getMyGlobalVariable : function() {
            return this.myGlobalVariable;
        }
    
    }); // eo extend
    
    Ext.reg('mypanel', yournamespace.MyPanel);
    

提交回复
热议问题