【发布时间】:2013-08-19 01:58:00
【问题描述】:
我知道为了让网格显示父 div 需要一个特定的高度。现在我希望网格根据行数缩小或增加高度。
【问题讨论】:
我知道为了让网格显示父 div 需要一个特定的高度。现在我希望网格根据行数缩小或增加高度。
【问题讨论】:
以下内容将使网格的最大高度为 300 像素,但如果仅显示几行,则会缩小它。
父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();
}
});
【讨论】: