2016-11-25 39 views
0

我做了一個由ExtJS 3.4 GridPanel,高度:200。我有時需要改變高度。ExtJS網格將不會刷新setHeight後

當我setHeight(65)使其縮短,然後將setHeight恢復到它的原始高度:200時,網格似乎會返回到具有邊框的200高度,但其內部的內容保持原樣,因爲我將它設置爲65. 高度我曾嘗試以下調用setHeight後,但沒有運氣:

 grid.setHeight(200); 
    //myStore.load(); 
    //myStore.reload(); 
    //myStore.getStore().load(); 
    //grid.render(); 
    //grid.getView().refresh(); 
    //grid.getView().refresh(true); 
    //grid.getView().updateLayout(); 
    //grid.doLayout(); //just tried not okay 

the grid won't refresh

//the code: 
 
    grid = new Ext.grid.GridPanel({ 
 
     id: "myGrid", 
 
     store: myStore, 
 
     selModel: mySelectionModel, 
 
     columns: [ 
 
      mySelectionModel, 
 
      { 
 
       id: 'name', 
 
       header: "Item", 
 
       width: 240, 
 
       menuDisabled: true, 
 
       dataIndex: 'name' 
 
      } 
 
     ], 
 
     height: 200, 
 
     width: 280, 
 
     listeners: { 
 
      "keydown": function (e) { 
 
       if (e.getKey() == 17) { 
 
        mySelectionModel.clearSelections(); 
 
       } 
 
      } 
 
     } 
 
    }); 
 
//another item on top of the gird enlarged code here, so shorter the grid: 
 
grid.setHeight(65) 
 
//the item on top returned to be smaller code here 
 
//so then I return the height of the grid to its original in the line below: 
 
grid.setHeight(200); 
 
//however, after the above line, the content remains as the height of 65

+0

請問您可以添加一個簡單的小提琴嗎? –

+0

或者只是添加更多的代碼?什麼是網格?網格或網格視圖? –

回答

-1

設置新的寬度後嘗試此操作 grid.doLayout();

Try the below fiddle 

jsfiddle.net/praveensov/7kpZ9/737 這是用設置高度

+0

它不工作>。< – Todayboy

+0

http://jsfiddle.net/praveensov/7kpZ9/736/試試這個 –

+0

http://jsfiddle.net/praveensov/7kpZ9/737/這是更新小提琴與設置高度 –

0

奇怪更新小提琴。我試圖簡化代碼,即使在改變高度後,網格內容高度也能正確設置。你的父容器使用什麼佈局?

例(https://fiddle.sencha.com/#view/editor&fiddle/1l7c):

Ext.onReady(function() {  
    var grid = new Ext.grid.GridPanel({  
    title: 'People',  
    renderTo: Ext.getBody(),  
    store: new Ext.data.JsonStore({  
     fields: [ 'id', 'name' ],  
     data: [  
     { id: 1, name: 'Jack' },  
     { id: 2, name: 'Brian' },  
     { id: 3, name: 'John' },  
     { id: 4, name: 'James' },  
     { id: 5, name: 'Anna' },  
     { id: 6, name: 'Dorothy' },  
     { id: 7, name: 'Mike' },  
     { id: 8, name: 'Daisy' },  
     { id: 9, name: 'Brian' },  
     { id: 10, name: 'Brian' }  
     ]  
    }),  
    columns: [  
     { header: "Id", width: 50, menuDisabled: true, dataIndex: 'id' },  
     { header: "Name", width: 150, menuDisabled: true, dataIndex: 'name' }  
    ],  
    height: 200,  
    width: 280  
    });  

    grid.setHeight(60);  
    grid.setHeight(200);  
    grid.setHeight(90);  
    grid.setHeight(150);  
}); 
+0

只是嘗試,如果設置高度和一起短它確實返回相同的表,但在我的代碼中,我有擴大所有項目和另一個功能縮短所有項目的功能。網格在Ext.panel裏面,不知道是不是原因,讓我試着簡化我的代碼並提供更多的小提琴。 – Todayboy

0

我終於想通了怎麼辦!感謝您的所有努力。對不起,代碼太多了,所以我沒有在一開始就詳細說明。 網格位於Ext.TabPanel的第三個選項卡內,實際上,當我想將所有項目恢復到正常狀態時,視圖將返回到第一個選項卡。 所有我需要做的事情如下:

myContainer = new Ext.TabPanel({ 
//other properties of TabPanel 
    listeners: { 
    "tabchange": function (tabpanel, tab) { 
    if (tab.tabid == 3) { //the tab where the grid are 
     grid.getView().refresh(); 
    } 
})