- 我有一个带有初始标题列宽度的声明性 dojox.grid.datagrid。我有一个文本框。我的需要是
在 UI 中,如果用户在文本框中输入任何值,则该值应设置为列标题的动态宽度。
<div class="claro" id="dfgdfgd" name="dataGrid" onclick="setWidgetproperty(this.id,'xy','inner__dfgdfgd');" ondblclick="editCustomGrid(this.id)" onmouseup="setDocStyle(this.id)" style="height:200px; left:42px; position:absolute; top:89px; width:950px;"> <table class="claro" dojotype="dojox.grid.DataGrid" id="inner__dfgdfgd" rowselector="10px" style="height: 180px; width: 300px;"> <thead> <tr> <th field="Column1" id="Column1" noresize="true" width="100px"> <label id="Column1" onclick="getCustomGridColName(this.id,'inner__dfgdfgd');" style="cursor:pointer; font-family: Times; font-size:12pt;"> Column1 </label> </th> <th field="Column2" id="Column2" noresize="true" width="100px"> <label id="Column2" onclick="getCustomGridColName(this.id,'inner__dfgdfgd');" style="cursor:pointer; font-family: Times; font-size:12pt;"> Column2 </label> </th> </tr> </thead> </table> <input id="hidden__dfgdfgd" name="dataGrid" style="display:none;" type="hidden">
我可以使用下面的代码获取特定列的宽度。如何将此宽度设置回文本框值。
dojo.forEach(dijit.byId(tableID).layout.cells, function(cell,idx){
if(cell.field == id){
headerWidth = cell.width;
alert(headerWidth);
}
});
最佳答案
有一个名为 setCellWidth()
的方法(您可以在 API Documentation 中阅读它),您可以使用它来更改单元格的宽度。
您需要完成的唯一步骤是更新列(以便更改可见)。此步骤可以通过 cell.view.update();
完成。
注意:使用 grid.update()
或 grid.sizeChange()
更新整个网格是不够的,因为它只会更新列标题。 (这是我注意到的。)
因此,在您的 forEach
循环中,您将执行以下操作:
grid.setCellWidth(idx, "200px");
cell.view.update();
我还制作了一个可用的 JSFiddle,您可以查看 here .
关于javascript - 动态设置dojox.grid.datagrid标题列宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15826506/