2013-04-05 114 views
2
  • 我有一个带初始标题列宽的声明性dojox.grid.datagrid。我有一个文本框。我的需求是
  • 在用户界面中,如果用户输入任何值到文本框,该值应设置为列标题的动态宽度。动态设置dojox.grid.datagrid标题列宽度

    <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); 
       } 
      }); 
+0

你有它吗? :) – mschr 2013-04-05 13:03:45

回答

2

有一个名为setCellWidth()方法(可以在API Documentation读到它),其可用于改变细胞的宽度。

然后您需要完成的唯一步骤是更新列(以便更改可见)。此步骤可以使用cell.view.update();完成。

请注意:使用grid.update()grid.sizeChange()更新整个网格是不够的,因为它只会更新列标题。 (这东西我注意到了。)

因此,在您forEach循环,你会做这样的事情:

grid.setCellWidth(idx, "200px"); 
cell.view.update(); 

我也做了工作的jsfiddle其中您可以查看here

+0

非常感谢Dimitri M – Rachel 2013-04-05 06:40:41

+0

是否可以使用onResizeColumn(cellIdx)事件重新调整列的宽度 – Rachel 2013-04-05 11:55:42

+0

我不明白为什么不可以。你可以在你的事件处理程序中编写相同的foreach循环。 – g00glen00b 2013-04-05 12:10:53