【问题标题】:How to switch between 2 components in Ext JS BorderLayout region如何在 Ext JS BorderLayout 区域中的 2 个组件之间切换
【发布时间】:2011-03-05 17:42:59
【问题描述】:

我在这里创建了网格面板视口的 2 个区域(西部和中心), 现在我想要的是我想动态改变中心的“xtype”

目前“xtype”是“examplegrid”,我想将其更改为“eontable” 当我点击“西部”区域的列时......

这里是代码:用于 extjs

(

function output()
 {

    Ext.ns('supplierlist');
    Ext.BLANK_IMAGE_URL = '/extjs/ext/resources/images/default/s.gif';

    /********************************Code For Suppliers*****************************/

}
//end function var_dump
supplierlist.Grid = Ext.extend(Ext.grid.GridPanel, {
    initComponent: function() {
        var config = {
            store: new Ext.data.JsonStore({
                id: 'supplier',
                totalProperty: 'totalcount',
                root: 'rows',
                url: 'get_suppliers_list.php',
                fields: [{
                    name: 'supplier'
                }]
            }),
            columns: [{
                id: 'supplier',
                header: 'Suppliers List',
                width: 40,
                sortable: true,
                dataIndex: 'supplier'

            }],
            viewConfig: {
                forceFit: true
            }
        }
        this.addListener('click',
        function(val) {


            });
        Ext.apply(this, Ext.apply(this.initialConfig, config));
        supplierlist.Grid.superclass.initComponent.apply(this, arguments);

    }

    ,
    onRender: function() {
        // call parent
        supplierlist.Grid.superclass.onRender.apply(this, arguments);

        // load the store
        this.store.load({
            params: {
                start: 0,
                limit: 20
            }
        });


    }
    // eo function onRender
});

 Ext.reg('printsuppliers', supplierlist.Grid);


 Ext.ns('Example');


// example grid pre-configured class
 Example.Grid = Ext.extend(Ext.grid.GridPanel, {
    initComponent: function() {
        var config = {
            store: new Ext.data.JsonStore({
                //                              
                id: 'company'
                ,
                totalProperty: 'totalCount'
                ,
                root: 'rows'
                ,
                url: 'get-grid-data.php'
                ,
                fields: [

                ]
            })
            ,
            columns: [{
                id: 'Smart Metering'
                ,
                header: "Smart Metering"
                ,
                width: 40,
                sortable: true

            }
            ]
            ,
            viewConfig: {
                forceFit: true
            }
        };
        // eo config object
        // apply config
        Ext.apply(this, Ext.apply(this.initialConfig, config));

        this.bbar = new Ext.PagingToolbar({
            store: this.store
            ,
            displayInfo: true
            ,
            pageSize: 20
        });

        // call parent
        Example.Grid.superclass.initComponent.apply(this, arguments);
    }
    // eo function initComponent

    ,
    onRender: function() {

        // call parent
        Example.Grid.superclass.onRender.apply(this, arguments);

        // load the store
        this.store.load({
            params: {
                start: 0,
                limit: 20
            }
        });

    }
    // eo function onRender
});
 Ext.reg('examplegrid', Example.Grid);





 Ext.ns('eon');


// example grid pre-configured class
 eon.Grid = Ext.extend(Ext.grid.GridPanel, {
    initComponent: function() {
        var config = {
            store: new Ext.data.JsonStore({
                //                              
                id: 'company'
                ,
                totalProperty: 'totalCount'
                ,
                root: 'rows'
                ,
                url: 'get-grid-data.php'
                ,
                fields: [

                ]
            })
            ,
            columns: [{
                id: 'dummy'
                ,
                header: "dummy"
                ,
                width: 40,
                sortable: true

            }

            ]
            ,
            viewConfig: {
                forceFit: true
            }
        };
        // eo config object
        // apply config
        Ext.apply(this, Ext.apply(this.initialConfig, config));

        this.bbar = new Ext.PagingToolbar({
            store: this.store
            ,
            displayInfo: true
            ,
            pageSize: 20
        });

        // call parent
        eon.Grid.superclass.initComponent.apply(this, arguments);
    }
    // eo function initComponent

    ,
    onRender: function() {

        // call parent
        eon.Grid.superclass.onRender.apply(this, arguments);

        // load the store
        this.store.load({
            params: {
                start: 0,
                limit: 20
            }
        });

    }
    // eo function onRender
});
 Ext.reg('eontable', eon.Grid);


 Ext.onReady(function() {

    Ext.QuickTips.init();

    // create viewport with border layout
    var viewport = new Ext.Viewport({
        layout: 'border'
        ,
        id: 'vp'
        ,
        items: [{
            region: 'center'
            ,
            layout: 'fit'
            ,
            title: 'Center'
            ,
            xtype: 'examplegrid'
        },
        {
            region: 'west'
            ,
            title: 'Suppliers'
            ,
            width: 220
            ,
            xtype: 'printsuppliers'
            ,
            split: true
            ,
            collapsible: true
        }]
    });

});

}`)

代码 对于php

(`

$start = @$_REQUEST["start"];
 $limit = @$_REQUEST["limit"];

 $start = $start ? $start: 0;
 $limit = $limit ? $limit: 5;

 $data = array(
array("supplier" = >'a1'),
array("supplier" = >'a2'),
array("supplier" = >'a3'),
array("supplier" = >'a4'),
array("supplier" = >''),
array("supplier" = >''),
array("supplier" = >''),
array("supplier" = >''),
array("supplier" = >''),
array("supplier" = >''),
array("supplier" = >'')
);
 $a = array();
 $limit = ($limit > count($data)) ? $limit = count($data) : $limit;
for ($i = $start; $i < $start + $limit; $i++) {
    $a[] = $data[$i];
}


$o = array(
"success" = >true
, "totalCount" = >sizeof($data)
, "rows" = >$a
);

 echo json_encode($o);

// eof
 ? >

)

【问题讨论】:

  • 考虑格式化您的代码,因为它目前不可读(使用 4 个空格正确缩进)。还可以考虑为您的问题提供更有意义的标题。

标签: extjs


【解决方案1】:

我不会尝试使用您的示例代码,因为它目前一团糟。但是,根据您的描述,您似乎最好探索 CardLayout。

将您的中心区域定义为:

{
    id: 'center',
    region: 'center',
    layout: 'card',
    border: false,
    activeItem: 0,
    items: [
        {
            itemId: 'examplegrid',
            xtype: 'examplegrid'
            // other config properties here as needed
        },
        {
            itemId: 'eontable',
            xtype: 'eontable'
            // other config properties here as needed
        }
    ]
};

然后在另一个区域中操作适当的控件时在卡片之间翻转:

Ext.getCmp('center').getLayout().setActiveItem('eontable');
// or...
Ext.getCmp('center').getLayout().setActiveItem('examplegrid');

请注意,这种技术保留了两种面板类型的单例实例。您也可以将其中一个面板留在中心区域的初始定义之外,并在交换时动态创建和销毁面板。下面是从 'examplegrid' 更改为 'eontable' 的示例:

var center = Ext.getCmp('center');

center.add(Ext.ComponentMgr.create({
    itemId: 'eontable',
    xtype: 'eontable'
    // other config properties
}));

center.getLayout().setActiveItem('eontable');

center.remove('examplegrid', true);

随后将使用类似的操作从“eontable”切换回“examplegrid”。

【讨论】:

  • 这是正确的,边框布局不允许您更改在其区域之一内显示的面板。因此,在其中一个区域中嵌套卡片布局就可以了
  • @Juan,这是否也意味着环绕布局不能是边框布局?或者这仅适用于您要删除的项目的布局(意味着嵌套项目的卡片布局)?几周来我一直在尝试用边框布局解决这个问题,一个答案说使用 Ext.id() 来获取唯一的 id,但后来我使用我设置的 itemId 让我的控制器逻辑变得简单,我是试图在商店中管理这些 id,而我没有使用框架来解决这个问题是愚蠢的。
  • 如果您可以在这里使用卡片布局示例给出可行的建议,那就太棒了。 stackoverflow.com/questions/18630245/…
  • 如果我有三个或更多组件,它将如何工作。
【解决方案2】:

在边框布局的文档中有一个例子:http://www.sencha.com/deploy/dev/docs/?class=Ext.layout.BorderLayout

【讨论】:

    猜你喜欢
    • 2016-03-08
    • 2021-12-20
    • 1970-01-01
    • 1970-01-01
    • 2021-05-26
    • 2011-02-19
    • 1970-01-01
    • 2016-03-04
    • 1970-01-01
    相关资源
    最近更新 更多