stacks
stacks

Reputation: 67

Disable item inside combo box SAPUI5

I have a combo box with, let's say, 2 items.

one of the items has relevant data to report, and the other doesn't.

How would I grey out the unwanted item in the combo box?

I can grey out the entire combo box, but I'm not sure how to grey out items inside a combo box (this combo box is populated by an ODATA call).

Upvotes: 1

Views: 4687

Answers (2)

Inizio
Inizio

Reputation: 2256

You can use the property enabled of sap.ui.core.Item. Updated your oData and add one more boolean property like isRelevant which tell which item is enabled/disabled.

XML View

<ComboBox items="{path: '/YourBindingPath'}">
  <core:Item key="{key}" text="{text}" enabled="{enabledProperty}" />
</ComboBox>

JS view

var oItemTemplate = new sap.ui.core.ListItem({
  key: "{key}", 
  text: "{text}", 
  enabled: "{enabledProperty}"
});
var oComboBox = new sap.m.ComboBox({
  items: { 
    path: "/YourBindingPath", 
    template: oItemTemplate 
  }
});

Upvotes: 3

Nandan Chaturvedi
Nandan Chaturvedi

Reputation: 1098

You can set the items of the combo box to the disabled as follows:

Want to disable the selected item from combo box list:

this.getView().byId("idOfYourComboBox").getSelectedItem().setEnabled(false);

Based on the index of the items in the list.

this.getView().byId("idOfYourComboBox").getItems()[1].setEnabled(false);

Also, you can do the same thing based on the key like:

this.getView().byId("idOfYourComboBox").getItemByKey("keyName")

Let me know if this helps.

Upvotes: 0

Related Questions