禁用datagrid / enhancedgrid中的特定行

时间:2012-08-24 13:44:39

标签: dojo

我想以下列方式禁用datagrid中的一个特定行:

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

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

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

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

2 个答案:

答案 0 :(得分: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>作为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);
}

答案 1 :(得分: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
    }
}
相关问题