Detach Event on dhtmlxGrid

I am working on an application wherein I attach a mouse over event to a grid.



var eventId = grid.attachEvent(“onMouseOver”,function(id,ind)

{



return false;

});



Based on a condition I detach the same event from this grid.



if (…)

grid.detachEvent(eventId);



I cannot get the above to work.

Am I missing something here?



Thanks,

Rahul Kulkarni

Could you please provid us any kind of sample where we can reproduce this issue?

Probably issue appears because of you using local variable for event id (var eventId) and when you are trying detach event, “eventId” variable is not defined.



I have the following error handler which defines and attaches to a grid the mouseOver event.

function processErrors(r,c,message)
{
    grid.setRowColor(grid.getRowId®,“yellow”);
    grid.cellByIndex(r,c).cell.style.color=“red”;
    grid.cellByIndex(r,c).cell.style.fontWeight=“bold”;
    
    var eventId = grid.attachEvent(“onMouseOver”,function(id,ind)
    {
        this.cellByIndex(r,c).cell.title=message;   
        return false;
    });
    eventsArray[eventsArrayIndex++] = eventId;
}

I have another function which after a user has seen the errors from above, clears the mouseOver events.

function clearErrors()
{
    for (var i=0;i<eventsArray.length;i++)
    {
        //when I add an alert here I do see the events that I had attached previously.
       grid.detachEvent(otlGlobals.eventsArray[i]);
    }
}

Both the eventsArray and eventsArrayIndex are globally defined.


We have tested your code and it works perfect if modify clearErrors() function like that:


function clearErrors()
{
for (var i=0;i<eventsArray.length;i++)
{
grid.detachEvent(eventsArray[i]);
}
}

I am sorry about the typo in my clearErrors().
I do use it the way your email shows it.
The mouseOver events don’t detach though.
I am using v.1.6 build 80603 if that helps in any way…

Thanks.

Could you please send us example where we can reproduce this issue including files which you are using to init grid.