2013-08-16 63 views

回答

1

以下將給出網格的最大高度爲300px,但如果只有幾行顯示,則會縮小網格。

父DIV

var divGrid = domConstruct.toDom("<div id='divGrid' style='height:300px;'></div>"); 
domConstruct.place(divGrid, dojo.byId('Contents')); 

創建網格

var grid = new DataGrid({ 
    id: 'grid', 
    store: store, 
    structure: layout, 
    style: "height:300px", 
    loadingMessage: "Loading...", 
    noDataMessage: "No data...", 
    selectionMode: 'single', 
    rowSelector: '20px' 
}); 
grid.placeAt(divGrid); 
grid.startup(); 

現在電網加載後

dojo.connect(grid, '_onFetchComplete', function() { 
    var list = query('#grid .dojoxGridContent'); 
    var height = list[0].offsetHeight + 25; // additional 25 to account for headers 
    if (height < 300) { 
     dojo.byId("divGrid").style.height = height + 'px'; 
     dojo.byId("grid").style.height = height + 'px'; 
     grid.resize(); 
     grid.update(); 
    } 
});