Recently, I got a requirement to add an option “Select All” to the Multi Combo Box. I want to share my approach to achieve this functionality.
My Approach for the Solution:
I have downloaded code from SAPUI5 Samples for Multi Combo Box and have made changes as per this requirement.
- Create a Multi Combo Box along with an event, which triggers at selection from drop down list.
- Load data from local Json file, add “Select All” record and finally add to JSON Model oMCBModel [We write this code in onInit Function]
- Now, we execute the code as is, we should be seeing “Select All” option in the drop down of Multi Combo Box
- Implement the logic for “Select All”. If “Select All” is selected then all the items should be selected and if “Select All” is unselected then, all the items should be removed from selection. We write the code in event “SelectionChange” of Multi combo Box
- With above function in place, if we click on “Select All” option then all the items are selected in the Multi Combo Box.
- If “Select All” is unselected then, all the items are removed from the selection.
Source code is available at below mentioned location