cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Filtering a UI5 ComboBox ( dropdown) while selecting

0 Likes
2,710

Dear experts,

I have the following scenario. I have an OData populated dropdown. Let's say they are populated with numbers from 1..100.

Now my business scenario would be, while selecting a uneven number to automatically filter the dropdown only with uneven numbers ( viceversa for even numbers).

In the change event ( defined in the xml) , I'm resetting the OData Model:

this.getModel("oDropdownsModel").setData({ numbers: aNumbers }, true);

Afterwards I am assigning the selected key previously stored in sNumber.

this.getView().byId(sId + "number").setSelectedKey(sNumber);

After execution, I get a strange dump: "Uncaught TypeError: Cannot read property 'isA' of undefined", followed by the fact that the selection doesn't dissapear

And I think this has to do when changing the dropdown value in the exact moment of the selection process.

Is there any way to solve this error? Any event onAfterClose of the dropdown that I can use?

FYI, as a temporary solution I manually closed the dropdown:

this.getView().byId(sId + "number").close();

But again this is not elegant, and I don't want errors in my console 🙂

Please let me know in the comments below.

Thanks in advance!

Alex

View Entire Topic
Sharathmg
Active Contributor

Avoid OData calls everytime user types something i.e. onChange/Livechange events. Its going to result in bad performance. Also bad idea of keep setting values to Control by ID for every type of user... prone to cause headaches to you later.

Instead, get the 1..100 values into controller and then apply filter on the data set. This way, filtering is almost with zero delay and on selection, you pull up the values.

If there are too many values, find other options like Help popover as combo box is not best suited for high no. of values. Refer: https://experience.sap.com/fiori-design-web/combo-box/