原因是,ContentPane 布局容器会评估是否有单个子级或多个子级。它以不同的方式处理大小 - 并且会知道 'isSingleChild' 和 child == 小部件。如果它识别出一个小部件,它会调用它的 resize 函数。
为此,您需要手动调用 resize - 使用ContentPane
网格的尺寸。这是一种方法,通过标记
<div id="searchCol" dojoType="dijit.layout.ContentPane" title="Find Results">
<script event="onShow" type="dojo/connect">
// onShow connect is 1 ms too early to connect, adding 'whenIdle'
setTimeout(function() {
dijit.byId('grid').resize(
dojo.getMarginBox('searchCol')
);
},1);
</script>
<!--REMOVE the searchStatus element and the dataGrid displays? -->
<div id="searchStatus"></div>
<!--REMOVE the searchStatus element and the dataGrid displays? -->
<table data-dojo-type="dojox.grid.DataGrid" data-dojo-id="grid" id="grid" data-dojo-props="rowsPerPage:'5', rowSelector:'20px'">
<thead>
<tr>
<th field="PARCELID">Parcel ID</th>
<th field="OWNERNME1" >Owner 1</th>
<th field="OWNERNME2">Owner 2</th>
<th field="RESYRBLT ">Year Built</th>
<th field="SITEADDRESS" width="100%">Address</th>
</tr>
</thead>
</table>
<button id="clearSearch" dojoType="dijit.form.Button" type="button" onclick="clearSearchResults()" title="Clear Search Results" label="Clear Results"
iconClass="clearSearchBtn" style="position:absolute; bottom:7px;cursor:pointer; visibility:hidden"></button>
</div>
当然,这将消耗完整大小,并且不会遗漏按钮和搜索状态。你需要一个计算来做到这一点。类似于:
var size = dojo.getMarginBox('searchCol');
size.h = size.h
- dojo.getMarginBox(dojo.byId('searchStatus')).h
- dojo.getMarginBox(dojo.byId('clearSearch')).h;
dijit.byId('grid').resize(size);