如何在dojox数据网格中禁用或启用编辑,以便在dojox数据网格中获得选择单元I.E

想象一下我在数据网格中有两个列(a,b)。我希望B的列值是基于列A的值来编辑的。我在堆栈溢出中看到了一个解决方案,该解决方案特定于Dojo版本。我想知道是否有API,我们可以实现上述目标。

有帮助吗?

解决方案

我的首选方法是覆盖

canEdit: function(inCell, inRowIndex)

DataGrid的方法。从中,您可以获得项目:

this.getItem(inRowIndex) 然后如果它应该是可编辑的或不可编辑的,并且返回true / false,则返回。

这确实会覆盖列上的可编辑标志,因此如果需要,您需要使用该标志。

其他提示

没有api。最近我也有类似的要求,这里是我实现它的方式:

1)最初列B是可编辑的,因为我在网格的字段部分中进行了 2)使用OnroWlick捕获行的渲染。这样的东西应该做到

dojo.connect(grid, "onRowClick", grid, function(evt){
  var idx = evt.rowIndex,
  item = this.getItem(idx);

  //  get a value out of the item
  msname = this.store.getValue(item, "msname");
  if(msname != null &U& (trim(msname) == trim(offsetName))) {
    dojox.grid.cells._Base.prototype.format(idx, item);
  }
});
.

以下方法然后禁止内联编辑所需列。我们将行索引和列索引传递给以下功能:

dojox.grid.cells._Base.prototype.format = function(inRowIndex, inItem){
    var f, i=grid.edit.info, d=this.get ? this.get(inRowIndex, inItem) : (this.value || this.defaultValue);
    d = (d && d.replace && grid.escapeHTMLInData) ? d.replace(/&/g, '&amp;').replace(/</g, '&lt;') : d;

                //Check inRowIndex and inItem to determine whether to be editable for this row here.

    if(this.editable && (this.alwaysEditing || (i.rowIndex==inRowIndex && i.cell==this))){
    return this.formatEditing(d, inRowIndex);
    }else{
    return this._defaultFormat(d, [d, inRowIndex, this]);
    }
}
.

希望有帮助。可能你可以添加一个jsfiddle,我们可以尝试修复它。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top