Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by udays on Jan 19, 2009 06:58
open dhtmlx forum
Combo box in Grid

I'm using a combo box inside a grid. The functionality which I needed was like 'when the user selects value from combo box it should update the database with the selected value. If user enters the data manually for the combo box field that value is supposed to be added to the combo box listing and updated in the database.'

mygrid.attachEvent("onEditCell",onEditCell);

//called each time when cell changed
function onEditCell(stage,id,index,value){
    if(stage==2){
        alert(id+"__"+index+"__"+value);
    }
    return true;
}

With this event I can grab the value which is selected by the user from the combo box listing and update the database but I could not get the value which is manually entered by the user for combo box. I read from other Q and A's that "The event will occur when text changed and focus moved outside of control" but that couldn't help me to grab the manually entered value. Any suggestions?
Answer posted by Support on Jan 19, 2009 08:47
In order to know if an option with a certain value is presented in options list, you can use getOption(value) method of the combo. This method returns the option if it exists and null in the other case.

So, the approach can be the following:

mygrid.attachEvent("onEditCell",function(stage,id,index,value){
    if(stage==2){
        var combo = mygrid.getColumnCombo(index);
        var z=combo.getOption(value);
        if(!z) combo.addOption(value,value);
        ...
     }
     return true
})

Answer posted by uday on Jan 19, 2009 08:56
Thanks for the quick reply. The problem is that I can not get the value which I typed in the combo to the function atall. When I do an alert for the 'value' it shows me either the previous value or null(if it does not have a prev value) but not the value which I typed in. Any suggestions?