2013-04-10 2 views
0
  • 선언적 dojox.grid.datagrid에서 테이블 태그에 onresizecolumn을 사용하고 있습니다.

onresizecolumn = "columnResize (this.id, this.cellIdx)"함수를 호출 onresizecolumn선언적 dojox.grid.datagrid의 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의 어떤 버전입니까? 경고 (id) = inner__eterte 및 경고 (index) = undefined에 대한 –

+0

. dojo version = 1.7 – Rachel

답변

1

API documentation을 읽음으로써 Dojo 이 자동으로이 이벤트 핸들러에 셀 인덱스를 보내는 것으로 결론을 냈습니다. 그래서 해결책은 간단하게 다음과 같은 속성 onResizeColumn="myFunction"를 제공하고 다음과 같이 함수를 정의하는 것입니다 :이 작업을해야

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

, 난 그것을 테스트하기 위해 JSFiddle했다. 그건 그렇고 선언적 방식으로 모든 작업을 수행하려는 이유가 있습니까? 지금까지 경험 한 바에 따르면 JavaScript로 대부분의 내용을 작성하는 것이 훨씬 쉽습니다.

+0

감사합니다. 고마워. 이 방법으로 열 인덱스를 가져올 수 있습니까? onResizeColumn = "myFunction (this.id)"function myFunction (cellDx, tableID) { alert (cellDx); }. 테이블 ID와 인덱스가 필요합니다. 내 프로젝트 목적을 위해 선언적 방식이어야합니다. – Rachel

+0

이벤트 처리기는 셀 인덱스 만 반환하므로 저는 그렇게 생각하지 않습니다. 이벤트 처리기를 너무 많이 조작하지 않으면 작동하지 않거나 최소한 tableID는 작동하지 않을 것이라고 생각합니다. – g00glen00b

1

이 방법으로 작업 할 수 있습니다. 모범 사례인지 확실하지 않습니다.

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

HTML (제거 onresizecolumn 속성) (1.7+ 모듈 이름을 도장 사용)

<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, 위젯 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

함수에 전달 된 선택된 컬럼 인덱스를 찾는 방법을 찾지 못했습니다. –

+0

괜찮습니다. 바이올린은 위의 값 중 하나를 반환하지 않습니다. 다음 onheadercellclick = "getGridHeader (이벤트)"및 getGridHeader 함수 내부에서 event.grid.id 값을 얻을 수있는 테이블 태그에 하나 이상의 특성이 있습니다. 그럼 왜 onresizecolumn 속성에서는 불가능합니다. dojo-1.7/dojox/grid/_Grid.js에서 onresizecolumn 이벤트를 재정의해야합니까 – Rachel

+0

죄송합니다. url은 몇 가지 버전이 오래되었습니다. 결정된. –

관련 문제