0

我想以下列方式禁用数据网格中的一个特定行:

1)用不同的颜色突出显示一行

2)禁用该行的复选框/单选按钮选择

3) 禁用该行中存在的单元格的内联编辑,但允许其他行的内联编辑。

请。如果您有任何想法,请提供帮助。

4

2 回答 2

1

您可以使用以下功能的组合来提取内容

// as example, one of youre items uses identifier:'id' and 'id:10'
var identifier = '10'; 
var item = store._arrayOfTopLevelItems[10]; // you probably have this allready
var index = grid.getItemIndex(item);   // find which index it has in grid
var rowNode = grid.getRowNode(index);  // find a DOM element at that index

您将拥有<div>as rowNode,它包含一个带有单元格的表格(与您的列一样多)。设置它background-color

复选框的东西,你会知道它有哪个单元格索引

var cellNode = dojo.query('td[idx='+cellIndex+']', rowNode)[0];
// with cellType Bool, td contains an input
var checkbox = cellNode.firstChild;

编辑真的是另一家商店……在焦点处理程序中工作。要覆盖它,您必须保留不希望可编辑的行数组(尽管是单元格。editable == true)。

function inarray(arr, testVal) {
    return dojo.some(arr, function(val) { return val == testVal }).length > 0
}
grid.setNonEditable = function (rowIndex) {
    if(! inarray(this.nonEditable,rowIndex) ) 
           this.nonEditable.push(rowIndex);
}
grid.setEditable = function (rowIndex) {
    this.nonEditable = dojo.filter(this.nonEditable, function(val) { return val != rowIndex; });
}
var originalApply = grid.onApplyEdit
grid.onApplyEdit = function(inValue, inRowIndex) {
   if(! inarray(this.nonEditable,inRowIndex) )
        originalApply.apply(this, arguments);
}
于 2012-08-29T17:43:40.763 回答
0

如果您使用的是 dojox.grid.DataGrid 您可以使用 canEdit 函数来禁用行编辑或单元格编辑:

grid = new dojox.grid.DataGrid({
    canEdit: function(inCell, inRowIndex) {
        var item = this.getItem(inRowIndex);
        var value = this.store.getValue(item, "name");
        return value == null; // allow edit if value is null
    }
}
于 2014-04-30T09:04:48.070 回答