2013-04-05 111 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