Dynamically populating a dhtmlxcombo

How can we dynamically populate a a dhtmlx combo. Ususally combo is attached to dhtmlxgrid is called through the statement dhtmlxgrid.getCombo(0) when initializing the page where contents of combo are populated at start time using combo.put(value1,value1). How can we do this dynamically so that combo gets populated with a different value each time a coro cell is clicked.

Hi,

Since you are using a dhtmlxgrid, you can exploit onEditCell event , that gets called, for every cell edit action by a user. http://docs.dhtmlx.com/doku.php?id=dhtmlxgrid:event_oneditcell

You may define your onEditCellEvHandler . The handler is called at 3 stages, before edit of a cell, during edit, and after edit. (Read the docs, for expln). You may populate the “co” cell , at stage 1, that is , before edit begins.

grid.attachEvent("onEditCell", function(stage,rId,cInd,nValue,oValue){ switch(stage){ case 1: if(cInd == <requiredIndex> && rId == <requiredRId>){ var co = grid.cells(rId, cInd); co.clearAll(); // Put new values into co, using co.put() } return true; } } );

Is there any pre requisite before using the following statements:
“var co = grid.cells(rId, cInd);
co.clearAll();
co.put();”
because it gives an error saying object does not support this property or method.

The pre-requisite is that, the cell must be of excell type “co”, or “combo” , whatever it is that you are using.
This is because, only “co” and “combo” excell types provide functions, clearAll, etc…

A better programming practice would be to check the excell type of the cell, before you do the combo specific opreations, using grid.getColType();
OR
instead of
grid.cells(,);
you may use
grid.getCombo() or grid.getCustomCombo() , depending on what cell type you are using.

Grid column type is set to coro (mygrid.setColTypes(“coro,coro”);). Should we include any library files because still i am getting the same error “object does not support this property or method”.

Can you debug, and see which line exactly is throwing the error ?
Also, please copy-paste your entire code, relevant to this discussion.

Thanks.

The code is as follows:

mygrid.setColTypes(“coro,coro”);
mygrid.attachEvent(“onEditCell”, doOnCellEdit);

function doOnCellEdit(stage,rowId,cellInd)
{
if (stage == 0 && cellInd == 1)
{
var co = mygrid.cells(rowId,cellInd);
co.clearAll();
for(var i =0;i<typedata.length;i++)
{
co.put(typedata[i],typedata[i]); //typedata is an array which has data
}
}
return true;
}

Should i include any library files or am i missing anything in the above code?

Could you debug and see , which line is throwing this error ?
From the look of it, things look okay to me.

Is there any pre requisite before using the following statements:
If you are using co or coro, try to change it as

var co = grid.getCombo(cInd);
co.clearAll();
co.put();

Wouldn’t that mean , all combos in the column get the values?
Shouldn’t grid.cells(rowId, colIndex) return the excell of type that the grid cell actually is ?

grid.cells(rowId, colIndex) returns excell object, which controls edit process. But list of options is stored in single collection for whole column

If you want to access the options collection for the target cell only, you can use

grid.getCustomCombo(id, index)

but according to your use-case, it will not have any visible difference with previously suggested command.