Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Szymon Siewior on Mar 30, 2009 09:38
open dhtmlx forum
Grid selectbox events

Hello,

I created a multiline grid and set up a cell with a selectbox. This select box is in turn hooked up to an event (see below)

infogrid2.attachEvent("onCellChanged",
function(id,oldval,newval){
infogrid2.load('slabBuyerDetails.php?id=1&address='+newval);
}
);

Ultimately I want the select box to act as a switch to reload the grid with new values, but the event that I am using fires every time I change any cell (this happens when the grid reloads). Is there any event that would only react to this specific select box? I found an event onCheck but it only references to checkboxes/radios.

Help is greatly appreciated.

Answer posted by Support on Mar 31, 2009 05:59
You can use event parameters to detect which cell was affected and react only when necessary 

infogrid2.attachEvent("onCellChanged",function(id,ind,val){ 
            if (id == ID  && index == INDEX)
                  infogrid2.load('slabBuyerDetails.php?id=1&address='+newval);
});

where ID, INDEX - position of cell, which contains selectbox 

Answer posted by Szymon Siewior on Mar 31, 2009 07:27
This helped a lot but the script entered an infinite loop because after the grid reloaded, the field with selectbox was changed thus invoking the event. I added a trigger and another event to prevent that.

var switch_trigger=0;
infogrid2.attachEvent("onCellChanged",function(id,ind,val){ 
            if (id == ID  && index == INDEX && switch_trigger=0) {
                  infogrid2.load('slabBuyerDetails.php?id=1&address='+val);
                  switch_trigger=1;
            }
});
infogrid2.attachEvent("onXLE",function(gobj,cntrows){
           switch_trigger=0;
});


When the grid is being reloaded and the cell with the selectbox get's "edited" the event fails and script continues to load as intended. After the grid loads completely the switch is reset with the onXLE event.
Answer posted by Support on Mar 31, 2009 08:19
Yep, you are right , the original code has such problem. 
Your solution is correct, but as one more possible way to solve it - onEditCell event can be used, it similar to onCellChanged, but occurs only for changes triggered by user actions

infogrid2.attachEvent("onEditCell",function(stage,id,ind,val){ 
  if (id == ID && index == INDEX && stage==2)
          infogrid2.load('slabBuyerDetails.php?id=1&address='+newval); 
});

Answer posted by Szymon Siewior on Mar 31, 2009 08:35
Works like a charm! I think I will need to spend some more time with the Docs.