2013-04-10 32 views
0
  • 在聲明式dojox.grid.datagrid中,我在表標記中使用onresizecolumn。

onresizecolumn = 「columnResize(this.id,this.cellIdx)」在聲明式dojox.grid.datagrid的onresize列中獲取列索引

onresizecolumn調用一個函數。在調整特定的列我想獲得cellIdx。

<div class="claro" id="eterte" name="dataGrid" onclick="getConnect('inner__eterte');setWidgetproperty(this.id,'xy','inner__eterte');" ondblclick="editCustomGrid(this.id)" onmouseup="setDocStyle(this.id)" style="height:200px; left:39px; position:absolute; top:251px; width:950px;"> 
    <table class="claro" dojotype="dojox.grid.DataGrid" id="inner__eterte" onresizecolumn="columnResize(this.id,this.cellIdx)" rowselector="10px" style="height: 180px; width: 400px;"> 
      <thead> 
       <tr> 
        <th field="Column1" id="Column1_6" width="159px"> 
         Column1 
        </th> 
       </tr> 
      </thead> 
    </table> 
    <input id="hidden__eterte" name="dataGrid" style="display:none;" type="hidden"> 
</div> 

function columnResize(id,index){ 
      alert(); 
      alert(id); 
      alert(index); 
     } 
+0

有什麼錯誤?警報輸出的是什麼?什麼版本的Dojo?用於alert(id)= inner__eterte和alert(index)= undefined的 – 2013-04-10 09:20:27

+0

。 dojo version = 1.7 – Rachel 2013-04-10 09:38:59

回答

1

通過閱讀API documentation我得出的結論是,Dojo 自動發送Cell索引到事件處理程序。因此,解決辦法是簡單地提供以下特性onResizeColumn="myFunction",然後你像這樣定義一個函數:

function myFunction(cellDx) { 
    alert(cellDx); 
} 

這應該工作,我還送JSFiddle進行測試。順便說一下,你是否有理由以聲明的方式來做所有的事情?就我的經驗而言,用JavaScript編寫大部分代碼要容易得多。

+0

其工作。非常感謝。是否有可能以這種方式獲得列索引.. onResizeColumn =「myFunction(this.id)」function myFunction(cellDx,tableID){alert(cellDx); }。我需要表格ID和索引。對於我的項目目的,它應該是以聲明的方式.. – Rachel 2013-04-10 11:41:30

+0

我不這麼認爲,因爲你的事件處理程序將只返回單元格索引。我認爲通過操縱事件處理程序太多它都不會工作,或者至少tableID不會。 – g00glen00b 2013-04-10 13:27:56

1

我可以這樣工作,不知道這是否是最佳做法。

http://jsfiddle.net/gE8rH/6/

HTML(刪除onresizecolumn屬性):

<div class="claro" id="eterte" name="dataGrid" onclick="getConnect('inner__eterte');setWidgetproperty(this.id,'xy','inner__eterte');" ondblclick="editCustomGrid(this.id)" onmouseup="setDocStyle(this.id)" style="height:200px; width:950px;"> 
    <table dojotype="dojox.grid.DataGrid" id="inner__eterte" rowselector="10px" style="height: 180px; width: 400px;"> 
     <thead> 
      <tr> 
       <th field="Column1" id="Column1_6" width="109px">Column1</th> 
       <th field="Column2" id="Column1_7" width="109px">Column2</th> 
       <th field="Column2" id="Column1_8" width="109px">Column3</th> 
      </tr> 
     </thead> 
    </table> 
</div> 

JS(使用道場1.7+模塊名稱),分配給小部件的onResizeColumn屬性:

require(["dojo/parser", "dijit/registry", "dojox/grid/DataGrid"], function (parser, registry) { 
    parser.parse().then(afterParse); 

    function afterParse() { 
     var d = registry.byId("inner__eterte"); 
     console.log(d); 

     d.onResizeColumn = function (colIdx) { 
      console.log("columnResize"); 
      console.log("args", arguments); 
      console.log("this", this); 
      console.log("colIdx", colIdx); 
     }; 
    } 
}); 

輸出這個時調整第一列的大小:

columnResize 
args [0] 
this [Widget dojox.grid.DataGrid, inner__eterte] { _attachPoints=[4], _attachEvents=[1], _connects=[0], more...} 
colIdx 0 
+0

我找不到將選定列索引傳遞給函數的方法。 – 2013-04-10 10:15:56

+0

好的。小提琴沒有返回任何上述值。然後我在表格標籤中添加了一個屬性onheadercellclick =「getGridHeader(event)」,裏面的getGridHeader函數能夠獲取event.grid.id值等等。那麼爲什麼它不可能在onresizecolumn屬性中。我是否需要重寫dojo-1.7/dojox/grid/_Grid.js中的onresizecolumn事件 – Rachel 2013-04-10 10:31:08

+0

對不起,該網址是舊版本的幾個版本。固定。 – 2013-04-10 10:40:13