Question

How to disable or enable edit for selective cell in dojox data grid i.e

Imagine I have two columns (A, B) in a data grid. I want column value of B to be editable based on the value of column A. I have seen one solution in stack overflow which was specific to a DOJO version. I would like to know if there are APIs by which we can achieve above objective.

Was it helpful?

Solution

My preferred method is to override the

canEdit: function(inCell, inRowIndex)

method of the DataGrid. From that, you can get the item:

this.getItem(inRowIndex)

then work out if it should be editable or not, and return true/false.

This does override the editable flag on the column though, so you'll need to do something with that if needed.

OTHER TIPS

There is no API as such. I also had similar requirement recently and here is how I implemented it:

1) Initially the column B is editable because I made it so in the Fields section of grid 2) Use onRowClick to capture the rendering of rows. Something like this should do

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

The following method then disallows inline editing of required column. We are passing row index and column index to this following function:

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]);
    }
}

Hope that helps. Probably you can add a jsfiddle and we can try fixing it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top