DataCombo pre-selected value

ZEN, Caché

Hi everyone

I have a datacombo that displayes value from a db table.

I would like to set one of this value as default value. How can I do that? Is there a way to say selected value given the text or the Id from the DB table?

Thanks a lot and kind regards

Milena

  • 0
  • 0
  • 100
  • 0
  • 1

Answers

There are two ways - via client or server method:

===========================================================================================

Class ZENTest.ComboTest2 Extends %ZEN.Component.page
{

/// Load it in Samples Namespace
/// 
XData Contents [ XMLNamespace = "http://www.intersystems.com/zen]
{
<page xmlns="http://www.intersystems.com/zenxmlns:demo="http://www.intersystems.com/zendemotitle="Combobox Test Page">
<hgroup>
<group id="group">
</group>
<spacer width="200"/>
<dataCombo id="dataCombo1"
label="dataCombo1" name="dataCombo1"
editable="true"
  unrestricted="true"
searchKeyLen="0"
choiceColumn="1"
valueColumn="2"
maxRows="10000"
displayColumns="1,4,3"
dropdownWidth="50.0em"
sql="SELECT Name,ID,Title,SSN FROM ZENDemo_Data.Employee ORDER BY Name "
columnHeaders="Name,SSN,Title">
</dataCombo>
</hgroup>
</page>
}

ClientMethod onloadHandler() [ Language = javascript ]
{
   zenSetProp('dataCombo1','value', 'Adam,Lisa H.' );
   ///zenSetProp('dataCombo','value', "Please make a choice." );
}

Method %OnAfterCreatePage() As %Status [ GenerateAfter = %OnAfterCreatePage ]
{
   Set tHolder = %page.%GetComponentById("group")
    set tComp = ##class(%ZEN.Component.dataCombo).%New()
    set tComp.id = "dataCombo"
set tComp.label = "dataCombo"
set tComp.value = "Alton,George D."
/// set tComp.value = "Please make a choice"
set tComp.maxRows="10000"
set tComp.dropdownWidth="50.0em"
set tComp.valueColumn="2"
set tComp.choiceColumn="1"
set tComp.sql = "SELECT Name,ID,Title,SSN FROM ZENDemo_Data.Employee ORDER BY Name"
If $IsObject(tComp) {
Do tHolder.%AddChild(tComp)
}
&js<zen('dataCombo1').executeQuery();>
    Quit $$$OK
}

}
=========================================================================================