【问题标题】:Get column index in onresizecolumn of declarative dojox.grid.datagrid获取声明性 dojox.grid.datagrid 的 onresizecolumn 中的列索引
【发布时间】:2013-04-01 22:00:33
【问题描述】:
  • 在声明性 dojox.grid.datagrid 中,我在 table 标记中使用 onresizecolumn。

onresizecolumn="columnResize(this.id,this.cellIdx)"

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

【问题讨论】:

  • 有什么错误?警报输出什么?什么版本的道场?
  • 对于 alert(id) = inner__eterte 和对于 alert(index) = undefined。道场版本 = 1.7

标签: datagrid dojo dojox.grid.datagrid onresize


【解决方案1】:

通过阅读API documentation,我得出结论,Dojo 自动 将 Cell 索引发送到事件处理程序。所以解决方案是简单地提供以下属性onResizeColumn="myFunction",然后定义一个这样的函数:

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

这应该可以,我什至做了一个JSFiddle 来测试它。顺便说一句,你有什么理由想以声明的方式完成所有这些工作吗?就我的经验而言,用 JavaScript 编写大部分内容要容易得多。

【讨论】:

  • 它的工作。多谢。是否可以通过这种方式获取列索引.. onResizeColumn="myFunction(this.id)" function myFunction(cellDx, tableID) { alert(cellDx); }。我需要表ID和索引。出于我的项目目的,它应该以声明方式..
  • 我不这么认为,因为您的事件处理程序只会返回单元格索引。我认为过多地操纵事件处理程序都不会起作用,或者至少 tableID 不会。
【解决方案2】:

我可以通过这种方式使其工作,但不确定这是否是最佳做法。

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(使用 Dojo 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

【讨论】:

  • 我找不到将所选列索引传递给函数的方法。
  • 好的。小提琴没有返回任何上述值。然后我在表标签中还有一个属性为 onheadercellclick="getGridHeader(event)" 并且在 getGridHeader 函数内部能够获取 event.grid.id 值等等。那么为什么它在 onresizecolumn 属性中是不可能的。我是否需要覆盖 dojo-1.7/dojox/grid/_Grid.js 中的 onresizecolumn 事件
  • 抱歉,该网址有几个旧版本。固定。
  • onresizecolumn 由于某种原因似乎没有传递事件。
  • 好的..我的需要是声明式的。无论如何,谢谢 Paul Grime
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-03-31
  • 1970-01-01
  • 2011-10-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-16
  • 1970-01-01
相关资源
最近更新 更多