2011-05-17 68 views
4

予有這種類型的結構(內線3.3.1):ExtJS的:網格100%的高度

var page = new Ext.Viewport({ 
    layout: 'border', 
    anchor:'100% 100%', 
    renderTo: Ext.getBody(), 
    items: [{ 
     region: 'north', 
     height:'auto', 
     items: [toolbar] 
    },{ 
     region: 'center', 
     layout:'fit', 
     items: [gridCourses,gridExams] 
    }] 
}); 

在工具欄,我有兩個按鈕,課程和考試。我使用這些按鈕來顯示/隱藏兩個網格中的一個,這樣一次只能看到一個。我使用的按鈕的代碼是這樣的:

{ 
    text: 'Courses', 
    iconCls: 'show-courses', 
    handler: function(){ 
     gridCourses.store.reload(); 
     gridCourses.show(); 
     gridExams.hide(); 
    } 
},{ 
    text: 'Exams', 
    iconCls: 'show-exams', 
    handler: function(){ 
     gridExams.store.reload(); 
     gridCourses.hide(); 
     gridExams.show(); 
    } 
} 

的問題是:(?尤其是在高)我怎麼會有顯示的網格來填滿整個屏幕。我想我必須把東西放在按鈕的處理程序或聽衆的網格中,但我不知道該放什麼。任何提示?

回答

3

「適合」佈局僅適用於放置單個面板。使用「卡」的佈局,而不是兩個或兩個以上的面板之間切換它們共享同一個空間:

{ 
    region: 'center', 
    layout: 'card', 
    // 0 here means the zeroth element of the items array. 
    activeItem: 0, 
    items: [ 
     gridCourses, 
     gridExams 
    ] 
} 

你的按鈕處理則成爲:

{ 
    text: 'Courses', 
    iconCls: 'show-courses', 
    handler: function() { 
     gridCourses.getStore().reload(); 
     gridCourses.ownerCt.getLayout().setActiveItem(gridCourses); 
    } 
}, 
{ 
    text: 'Exams', 
    iconCls: 'show-exams', 
    handler: function() { 
     gridExams.getStore().reload(); 
     gridExams.ownerCt.getLayout().setActiveItem(gridExams); 
    } 
} 

而且,假設工具欄變量在你的例子中包含一個真實的Ext.Toolbar實例,你的佈局一般可以用不同的視口定義來改進:

new Ext.Viewport({ 
    layout: 'fit', 
    items: { 
     xtype: 'panel', 
     layout: 'card', 
     activeItem: 0, 
     tbar: [ 
      { 
       text: 'Courses', 
       iconCls: 'show-courses', 
       handler: function() { 
        gridCourses.getStore().reload(); 
        gridCourses.ownerCt.getLayout().setActiveItem(gridCourses); 
       } 
      }, 
      { 
       text: 'Exams', 
       iconCls: 'show-exams', 
       handler: function() { 
        gridExams.getStore().reload(); 
        gridExams.ownerCt.getLayout().setActiveItem(gridExams); 
       } 
      } 
     ], 
     items: [ 
      gridCourses, 
      gridExams 
     ] 
    } 
}); 

也就是說,如果由於其他原因您的視口仍然需要邊框佈局,那麼可以將卡面板,工具欄和全部卡片放置在中心區域,如答案的頂部所示。

+0

感謝這個輝煌的例子!真的很好,並解釋! – Danilo 2011-05-18 11:46:27

+0

沒有視口怎麼辦? – digz6666 2012-04-16 07:57:53

3

合適的佈局只支持一個元素,否則它想要工作。你需要把它包起來。

var page = new Ext.Viewport({ 
    layout: 'border', 
    // anchor:'100% 100%', <- I don't think you need this, cause the Viewport is alsways bound to the fullscreen 
    // renderTo: Ext.getBody(), <- Same here. The viewport is alsways rendered to the body 
    items: [{ 
     region: 'north', 
     height:'auto', 
     items: [toolbar] 
    },{ 
     region: 'center', 
     layout:'fit', 
     items: [ 
      { 
       xtype: 'container', 
       items: [ 
        { 
         xtype: 'container' 
         layout: 'fit', 
         items: [Grid1] 
        }, 
        { 
         xtype: 'container' 
         layout: 'fit', 
         items: [Grid1] 
        } 
       ] 
      } 
     ] 
    }] 
}); 
+0

@danilo我已經添加了一個應該工作的示例 – sra 2011-05-17 11:13:00

+0

嗨,謝謝你的例子。我嘗試了一個標準的,非常簡單的網格,但它沒有得到容器的高度,我只看到一排網格。如果我手動設置高度讓我們說500px,那麼我看到網格元素更大。關於你的代碼,我應該爲網格設置一些特殊的東西嗎? – Danilo 2011-05-17 11:42:31

+0

@danilo好吧,一會兒 – sra 2011-05-17 11:43:19