on 05-03-2016 3:53 AM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
One easy way is to set it as the first value in the OData response.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Refer the examples given here - SAPUI5 SDK - Demo Kit
You can find the source code for setting the initial value in the ComboBox control.
User | Count |
---|---|
82 | |
10 | |
10 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.