Cell click event in row selection mode

How to detect which cell is clicked in row selection mode?

Here’s a nice way to do it:

dhtmlXGridObject.prototype.onClick = function(cb){	
  var that=this;
  dhtmlxEvent(that['obj'],"click",function(e){
		if (that.getUserData('-1', "zeroRows")) return		
		var el  = that.getFirstParentOfType(_isIE?event.srcElement:e.target,"TD");
		var rId = el.parentNode.idd;
		var cId = el._cellIndex;
		var v   = that.cells(rId, 0).getValue()
    cb.apply(that, [rId, cId, v]);
	})
}

Then use it as:

  grid.onClick(function(rId, cId, value){
     console.log(arguments);
  });  

One thing… the line with the userdata is not needed:

dhtmlXGridObject.prototype.onClick = function(cb){	
  var that=this;
  dhtmlxEvent(that['obj'],"click",function(e){
		var el  = that.getFirstParentOfType(_isIE?event.srcElement:e.target,"TD");
		var rId = el.parentNode.idd;
		var cId = el._cellIndex;
		var v   = that.cells(rId, 0).getValue()
    cb.apply(that, [rId, cId, v]);
	})
}

I noticed the function (above) will sometime error if’

the grid has enableLightMouseNavigation set
the user is moving up and down the grid
while at the same time the user is rapidly clicking

The function will error maybe 1 in 30 clicks–really no big deal.

As it is very unlikely this is purpose of the grid, …click 1000 times as fast as you can and randomly hover over rows… Nonetheless, it can be detected, caught and handled:

dhtmlXGridObject.prototype.onClick = function(cb){ var that=this; dhtmlxEvent(that['obj'],"click",function(e){ var el = that.getFirstParentOfType(_isIE?event.srcElement:e.target,"TD"); var rId = el.parentNode.idd; var cId = el._cellIndex; if (rId == undefined || cId == undefined ) { app.cancelEvent(e); return; } var v = that.cells(rId, cId).getValue() cb.apply(that, [rId, cId, v]); }) } (the last line of the function was corrected as well)

Also use this:

var app ={}
app.cancelEvent=function(event) {
	if (event.preventDefault) 
		event.preventDefault();
	else 
		event.returnValue = false; 
}