在dojox数据网格中禁用或启用选择性单元格的编辑

时间:2012-10-02 12:33:36

标签: dojo dojox.grid.datagrid dojox.grid xpages-extlib

如何在dojox数据网格中禁用或启用选择性单元格的编辑,即

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

2 个答案:

答案 0 :(得分:2)

我首选的方法是覆盖

canEdit: function(inCell, inRowIndex)

DataGrid的方法。从那里,您可以获得该项目:

this.getItem(inRowIndex)

然后确定它是否应该可编辑,并返回true / false。

这确实会覆盖列上的可编辑标志,因此如果需要,您需要对其执行某些操作。

答案 1 :(得分:0)

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

1)最初,列B是可编辑的,因为我在网格的“字段”部分中这样做了 2)使用onRowClick捕获行的呈现。这样的事情应该做

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,我们可以尝试修复它。