Create table like structure using Extjs

爱⌒轻易说出口 提交于 2019-12-08 08:34:56

问题


In Extjs 4.1.1a, I am trying to create a table like structure using containers or panels which completely stretches horizontally and vertically to its parent component.

Here is the Example Fiddle

In View:

Ext.define("MyApp.view.Main", {
    extend: 'Ext.panel.Panel',       
    layout: {type: 'vbox',align:'stretch'},
    title: 'hello',
    id: 'mainContainer' 
})

In Controller:

var items = [];
for(var i=0;i<6;i++){

    var vContainer = [];
    var hContainer = [];
    for(var j=0;j<7;j++){
       hContainer.push({
         xtype: 'panel',
         flex:1,                            
       })                       
    }                       
    vContainer.push({
        xtype:'panel',
        flex: 1,
        layout: {type:'hbox',align:'stretch'},                          
        items: hContainer
    })
}

var mainController = Ext.getCmp('mainController');  //Calling the id here
mainController.add(items);  //adding the items variable which is mentioned above

I am not sure why this ain't working (not showing anything). Please assist me to solve this problem.


回答1:


Fiddle

You're pushing an array into an array and passing it as items in the main panel:

Here's the fixed code:

    var items = [];
    for(var i=0;i<6;i++){

        var vContainer; //THE PROBLEM - NO NEED FOR IT TO BE AN ARRAY
        var hContainer = [];
        for(var j=0;j<7;j++){
           hContainer.push({
             xtype: 'panel',
               title : 'H',
             flex:1,                            
           });                      
        }                       
        vContainer = {
            xtype:'panel',
            flex: 1,
            layout: {type:'hbox',align:'stretch'},
            title : 'V',
            items: hContainer
        }
        items.push(vContainer);
    }



Ext.create('Ext.panel.Panel',{
    renderTo: Ext.getBody(),
    layout: {type: 'vbox',align:'stretch'},
    title: 'hello',
    minHeight : 500,
    minWidth : 500,
    items: items        
})



回答2:


Edit: Was too late, leaving the example here anyway.

You're building it wrong:

/*****************************************/
    var items = [];
    for(var i=0;i<6;i++){               

        var hContainer = [];
        for(var j=0;j<7;j++){
           hContainer.push({
             xtype: 'panel',
             flex:1
           });                  
        }                       
        items.push({
            xtype:'panel',
            flex: 1,
            layout: {type:'hbox',align:'stretch'},                          
            items: hContainer
        });
    }

/*****************************************/

Ext.create('Ext.panel.Panel',{
    renderTo: Ext.getBody(),
    layout: {type: 'vbox',align:'stretch'},
    title: 'hello',
    height: 400,
    items: items        
});

Here's the fiddle: http://jsfiddle.net/johanhaest/ptZp7/



来源:https://stackoverflow.com/questions/15429321/create-table-like-structure-using-extjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!