Find a specific column in a dataCombo
Hello,
I've the below datacombo definition and when selecting an item from it and make this call:
var component=zen("Component").getProperty("value");
I would get the ID (first column) which is what I'm looking for
<dataCombo id="Component" name="Component" align="left" size="30" maxRows="400"
sql="select ID, name From MSDS_Serenity.Kit Where (? is null or %UPPER(name)[%UPPER(?)) And Loc=? AND Active=1 and ParentKit is not null and (RapidSterTemp != 1 or RapidSterTemp is null) and asset=0 order by name asc"
searchKeyLen="10"
editable="true"
required="false"
showEmpty="true"
displayColumns="1,2"
choiceColumn="2"
valueColumn="1"
dropdownWidth="230px" onchange="">
<parameter value="?" />
<parameter value="" />
<parameter value="" />
</dataCombo>
.png)
but when selecting an item from my grid that uses this code to populate the realated value in my dataComb
var cbComponent = zen("Component");
cbComponent.setValue(table.getRowData( table.selectedIndex).Component);
but now making the same call:
var component=zen("Component").getProperty("value");
I get nothing, so is there a function or attribute in data comb to find the value in a specific column?
.png)
Thanks
Comments
When you select an item normally from the dataCombo, the control already knows the row it selected, so getProperty("value") returns the value from valueColumn="1" — your ID. [1]
When you do this instead:
var cbComponent = zen("Component");
cbComponent.setValue(table.getRowData(table.selectedIndex).Component);
and then getProperty("value") returns nothing, the issue is that the combo may not know how to resolve the display/value pair when the value is set programmatically unless it can look up the display value for that ID. A matching sqlLookup is the suggested way to handle this. [2]
For a dataCombo, the first column of the SQL query is the actual value and the second column is the display value. In your case, that matches your definition with valueColumn="1" and choiceColumn="2", so the ID is the internal value and the name is the display value. [2][1]
You can define sqlLookup so the control can find the display text when you call setValue() with an ID, for example in the same pattern as:
sqlLookup="SELECT Name FROM MSDS_Serenity.Kit WHERE ID = ?"
This tells the page how to find the correct display value when the control value is changed programmatically. [2]
There is also evidence that by default a dataCombo may not load its contents until the user opens it. If needed, setting cached="1" makes it load when the page loads instead. [3]
So the value you want is still the value column, and the fix is not a special “find specific column” function, but making sure the combo can resolve programmatic values by using sqlLookup and, if necessary, cached="1". [2][3]
Sources: