0
votes

I wish to bind a filter dynamically in the controller of a xml view to a control in the view. I know how to do this but I don't find a proper way to do this initially.

E.g. I defined a ComboBox on the view and gave a binding path to the oData model (in the view). Then in the controller I wish to set a fiter on the items of the ComboBox. I tried in onInit of the view but there the binding is not yet set in the ComboBox object.

I solved it by doing a lazy loading and set the filter in the "loadItems" event. Is there any way to do this by not using lazy loading? Did not find a proper event or standard hook.

Thanks.

1
you dont need to do it 'outside' of the binding. check this page > help.sap.com/saphelp_nw74/helpdata/en/91/… - Ji aSH

1 Answers

1
votes

So the binding is not available in oninit()... Where exactly do you create the binding then the very first time??? Where ever you create the binding the first time you can also apply the initial filters.

For example, in the controller inside onInit you call this.byId("myComboBox") to get the control. Then you call oComboBox.bindItems({...}) and also pass the initial filters. So bindItems(...) also accepts filters. If the filters change you can simply call oComboBox.getBinding("items").filter(...) to update the filters. Check the worklist app tutorial for some details...

By the way, you could also directly specify the binding including filters in the XMLView directly. See my answer here for details.