I have a combo cell in a grid on which filtering has been enabled. Currently once a selection has been made and the user clicks inside the combo it only shows one option. What I would like to do is clear the text by code so that all the options are shown again and then the user can type new information to filter again.
Please can you tell me what is the best event and method to choose to do that.
If you want to clear combo text each time the editor is opened, you may try the following:
grid.loadXML(url,function(){
combo = mygrid.getColumnCombo(columnIndex); /*columnIndex is index of the combo column*/
combo.attachEvent("onOpen",function(){
this.setComboText("");
this.filterSelf();
})
});
function clearComboFilter()
{
gttOldComboVal = this.getSelectedValue();
this.setComboText("");
this.filterSelf();
}
function resetComboVal()
{
if(this.getComboText() == "")
{
this.setComboValue(gttOldComboVal);
}
}
The first I use on the onOpen event and works well. The second I use on the onBlur event and is really there if the user doesn’t choose anything then I want to replace the original value. Unfortunately that only works half way. i.e. the Value in the Combo is set back but for some reason the value is not returned to the underlying field in the cell.
Perhaps Alexandra or some one from DHTMLX can guide us on what to do. If the value could be returned to the underlying field then I think the above solution would work fine… for me at least.
Hi Alexandra, I’m not sure what this is trying to do. Are you saying that if the editCellEvent returned ‘true’ then the grid’s cell value would be updated by my resetComboVal function? Also should we not be testing to see if it’s NOT blank then return ‘false’. I only want to re-set the old value IF the user does NOT choose an option.
Anothe problem is that currently the 2 functions that I have are ‘generic’ i.e. they can be applied to any Combo as they use ‘this’. However what you are suggesting would require that every grid that has a combo column would need a separate piece of code, unless there was a way of passing the grid object to the resetComboVal function.
Thanks for your input and I look forward to your answer.
Are you saying that if the editCellEvent returned ‘true’ then the grid’s cell value would be updated by my resetComboVal function?
No, resetComboVal doesn’t relate this event handler. onEditCell event called in 3 stages:0,1 and 2. 2 stage occurs when editor (combo in the example) is going to be closed. If event handler returns true, the editor values becomes cell value and cell value doesn’t change in the other case.
Thanks for the reply. Adding the code at editcell event will call for all the cell’s in the grid. But we want the code to be called only for combo’s lost focus. Could you please help us in using onBlur event. We tried the same way but the onBlur event is not triggered for the combo when it lose the focus.
combo onBlur is called right before editor is closed (onEditCell in 2 stage). If you change grid value in onBlur event, this values will be reset by combo editor.
So, you need to use onEditCell. You may check column index and return false only for combo column.
Alexandra I haven’t had a chance to test out your suggestion regarding onEditCell event but the REAL ANSWER here is for the filter method on the combo to continue showing the options on either side of the selected value rather than removing them from the combo list.
That is the behaviour everyone is used to (thanks to Microsoft) and is probably easier to code than having to remove the options. i.e. as somebody types the system goes to the particular option starting with those characters but continues to show the other options on each side.