2011-03-07 40 views
9

下面的ExtJS的代碼創建兩個區域彼此的左邊和右邊,像這樣:如何在ExtJS表格佈局中對齊兩個區域?

enter image description here

我有什麼改變這個代碼,以便在兩個區域頂部對齊?

<script type="text/javascript"> 

    var template_topbottom_top = new Ext.Panel({ 
     frame: false, 
     border: false, 
     header: false, 
     items: [] 
    }); 

    var template_topbottom_bottom = new Ext.Panel({ 
     frame: false, 
     border: false, 
     header: false, 
     items: [] 
    });  

    var template_topbottom = new Ext.Panel({ 
     id:'template_topbottom', 
     baseCls:'x-plain', 
     renderTo: Ext.getBody(), 
     layout:'table', 
     layoutConfig: {columns:2}, 
     defaults: { 
      frame:true, 
      style: 'margin: 10px 0 0 10px; vertical-align: top' //doesn't work 
     }, 
     items:[{ 
       width: 210, 
       height: 300, 
       frame: false, 
       border: true, 
       header: false, 
       items: [template_topbottom_top] 
      },{ 
       width: 1210, 
       height: 200, 
       frame: false, 
       border: true, 
       header: false, 
       items: [template_topbottom_bottom] 
      } 
     ] 
    }); 

    replaceComponentContent(targetRegion, template_topbottom, true); 

</script> 
+0

提示:您正在嵌套組件。您的'template_topbottom'中的'items'應直接引用'template_topbottom_top'和'template_topbottom_bottom',而不是創建一個新的'items',並將它們作爲該陣列中孤獨的面板。另外,如果項目包含單個組件,則不需要用數組包裝它。 –

回答

1
<style> 
    .x-table-layout td { 
      vertical-align:top; 
    } 
</style> 
5

重用,我想補充一類風格,將永遠頂部對齊表格佈局單元格CSS文件。

<style> 
    .x-table-layout-cell-top-align td.x-table-layout-cell { 
     vertical-align: top; 
    } 
</style> 

這是優於所用.table-layout td作爲CSS選擇一個以前的答案,因爲如果你有此表佈局內的表中,選擇將頂部對齊所有細胞,而不僅僅是那些與表格的佈局相關。

你將這個類添加到您的Ext.Panel像這樣:

new Ext.Panel({ 
    cls: 'x-table-layout-cell-top-align', 
    layout: 'table', 
    items: [ 
     ... 
    ] 
}) 

如果你的面板已經有一個cls屬性,你可以用空格添加額外的類:

cls: 'my-container-cls x-table-layout-cell-top-align', 
9

在ExtJS的4,你可以使用tdAttrs配置選項:

layout: { 
    type: 'table', 
    columns: 2, 
    tdAttrs: { 
     valign: 'top' 
    } 
} 
+0

我最喜歡這個選項。 – Guus

2
  tdAttrs : { 
       style : { 
        verticalAlign : 'top' 
       } 
      }