简体   繁体   中英

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).

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 
  }
});

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM