Grid onclick question

Is it possible to know which column of the grid was clicked?

Or is it possible to know the cell contents when the grid is clicked?

Hello,

Unfortunately, onItemClick event does not get column id as an attribute.Try to use on_click collection that allows to define onclick handler for elements with a certain classname.

Grid cells - td elements with “dhx_td” class name. So, you can apply the following:

$$("mygrid").on_click["dhx_td"] = function(e,rowId,elem){ alert(elem.cellIndex) }

This works. Thank you.

I’ve noticed when a grid is placed inside of a popup window, the event continues to fire for all grids in the page.

What seems to be working is to add the onClick event during in onShow and then remove it during onHide.

$$("aPopup").attachEvent('onShow',  function(){
      $$("aGrid").on_click["dhx_td"] = function(e,rowId,elm){) }
})
$$("aPopup").attachEvent('onHide',  function(){
     $$("aGrid").on_click["dhx_td"] = null
 })

Actually,that didn’t work so well.

It seems this is defining an on click event for every grid, even the grids in other views:

$$("aGrid").on_click["dhx_td"] = function(e,rowId,elm){  console.log('xxxx'); ) }

Is there a way to restrict this for only the grid: $$(“aGrid”) ?

Hello,

Yes, there was a problem with sharing on_click collection. I have attached fixed libs, please try them.

That did not make a difference, the on click function is firing on all of the grids.

Hello,

Sorry, I attached old libs to previous post by mistake. Please try libs from the new attachment.
libs.zip (174 KB)

I am not sure if I was pointing to the new file when I was testing.

Anyway using the file you last provided is working great! As always, thank you.