Disable specific rows in datagrid/enhancedgrid

I want to disable one specific row in datagrid in following manner:

1) Highlight one row with a different color

2) Disable checkbox/radio button selection of that row

3) Disable inline editing of cells present in that row but allow inline editing for other rows.

Pls. help if you have any ideas.

Upvotes: 0

Views: 2974

Answers (2)

Vincnetas
Vincnetas

Reputation: 156

If you are using dojox.grid.DataGrid you can use canEdit function to disable row editing or cell editing :

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

Upvotes: 0

mschr
mschr

Reputation: 8641

You can use a combination of the following functions to extract stuff

// 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

You will have the <div> as rowNode, it contains a table with cells (as many as you got columns). Set its background-color

The checkbox thing, you will prly know which cell-index it has

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

Editing is another store really.. works in focus handlers. To override it, you must keep like an array of rows which you dont want editable (allthough the cell.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);
}

Upvotes: 1

Related Questions