cancel
Showing results for 
Search instead for 
Did you mean: 

How to set the default value to Combobox?

Former Member
0 Kudos

Hello Experts,

I have Two Combo Boxes, One is Dependent and Another and The values are Coming from ODATA to the Dropdown Boxes,

now i want to set one Default values to the Combo Boxes

Since it is Coming from ODATA am not able to find any answers

So, can anyone Suggest me something on this ???

Thanks in Advance,

Bharath

Accepted Solutions (0)

Answers (2)

Answers (2)

0 Kudos

Bharath,

Each item in the combobox has a key and there are properties available in the combobox as selectedKey & selectedItemId, you can set selectedKey as the  Key of the item you want to display.

Try out this, hope this will work.

Former Member
0 Kudos

Hi Deepak,

where should i mention that selected key and all, here i have attached my view code and Controller also pls share some links with examples,

here is my view code below

<Label text="QUARTER:" class="LabelStyle"/>

  <ComboBox id="idCombo" placeholder="Select Your Quarter" items="{OdataModel>/COMPARITIVE_ANALYSIS2}" selectionChange="onChange">

  <core:Item key="2015-Q1" text="{OdataModel>QUAR}" />

  </ComboBox>

  <Label text="MONTH:" class="LabelStyle"/>

  <ComboBox id="oComboBox" selectionChange="onSelect"></ComboBox>

  </l:content>

Controller code

Change: function(oEvent) {

    

          var oComboBox = this.getView().byId("oComboBox");

          if (oComboBox.getSelectedItem()) {

            //oComboBox.getSelectedItem().setText("");

            var cval=oComboBox.getValue();

            //alert(cval);

          }

          var oItem = oEvent.getParameter("selectedItem");

          alert(oItem);

          oComboBox.setSelectedItemId(oItem);

          var oContext = oItem.getBindingContext("OdataModel");

          var oQUARTER = oContext.getObject().QUAR;

    

          var oNewItem = new sap.ui.core.Item({

            text: "{OdataModel1>MONTH_YEAR}",

            key: "{OdataModel1>MONTH_YEAR}"

          })

          var oFilter = new sap.ui.model.Filter("QUAR", "EQ", oQUARTER);

          oComboBox.bindAggregation("items", {

            path: "OdataModel1>/COMPARITIVE_ANALYSIS1",

            group : true,

            template: oNewItem,

            filters: oFilter

          });

        },

      onSelect: function(oEvent) {

  //alert("aaa");

 

  var oComboBox = this.getView().byId("oComboBox");

        if (oComboBox.getSelectedItem()) {

          //oComboBox.getSelectedItem().setText("");

          var cval=oComboBox.getValue();

          //alert(cval);

Thanks in Advance,

Bharath

0 Kudos

Since it is property you need to put it in the xml view, where you have other properties defined for your control.

Here you can write it after   <ComboBox id="idCombo" .......

If you need examples then please go through the UI5 demo kit and  see few examples in the explored section.


SAPUI5 Explored


Former Member
0 Kudos

Thank you Deepak

Regards,

Bharath

kammaje_cis
Active Contributor
0 Kudos

One easy way is to set it as the first value in the OData response.

Former Member
0 Kudos

How to set ??

I am very new to SAPUI5. please

Thanks in Advance,

Bharath

saurabh_vakil
Active Contributor
0 Kudos

Refer the examples given here - SAPUI5 SDK - Demo Kit

You can find the source code for setting the initial value in the ComboBox control.