cancel
Showing results for 
Search instead for 
Did you mean: 

Event when binding sap.m.Select is done

Former Member
0 Kudos

Hi,

I was wondering if there is an event that I can use for when my sap.m.Select control is bound.

The reason is that I use the selected key to bind the rest of my view:


view.bindElement("/ThesisSet('"

                                    + sap.ui.getCore().byId('masterSelect')

                                            .getSelectedKey() + "')");

I just want to bind the view with the first item of my 'ThesisSet'.

Thanks,

RW

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor

There is an event "DataReceived" from ODataListBinding

this.byId("SELECT").getBinding("items").attachEvent("dataReceived", fnFunction, oListener);

Former Member
0 Kudos

Hi Maksim,

Thanks for your reply!

I tested it, but maybe I'm placing the code in the wrong place...

I've put your code in the onAfterRendering function, but the problem is that getBinding() returns undefined... So the the items are not bound yet.

Thanks anyways,

RW

former_member182372
Active Contributor
0 Kudos

Robbe, where do you define binding for sap.m.Select? In xml or somewhere in controller?

Former Member
0 Kudos

In the controller in the onInit() function

former_member182372
Active Contributor
0 Kudos

Could you post a code? You can attach event once th binding is done, so in onInit

former_member182372
Active Contributor
0 Kudos

Robbe, i'v done someting like this many time and never had issues

oTable.bindItems("/Tracks", columnListItem, null, null);

var binding = oTable.getBinding("items");

binding.attachEvent("dataReceived", fnFunction, oListener);

Former Member
0 Kudos

Hi Maksim,

binding is undefinded... So the attachEvent method doesn't work. If I'd place these lines in a setTimeout function, it works:

var binding = oTable.getBinding("items");

binding.attachEvent("dataReceived", fnFunction, oListener);



But as we agreed that's a bad solution..


It just seems like the bindItems() function takes some time in my app.



Anyways, I appreciate your help.



RW




former_member182372
Active Contributor
0 Kudos

when you bind items use following

oSelect.bindAggregation("items", {

path : "/PATH",

template : temaplteObject,

events : {

     dataReceived : fnFunction

}

})

Former Member

Maksim, thanks for your reply. When I used the getSelectedKey method it still didn't work, but I found another way (the aKeys property )


sap.ui

                                .getCore()

                                .byId('masterSelect')

                                .bindAggregation(

                                        "items",

                                        {

                                            path : "/ThesisSet",

                                            template : seltemp,

                                            events : {

                                                dataReceived : function() {

                                                    view.bindElement("/"

                                                            + this.aKeys[0]);

                                                    sap.ui

                                                            .getCore()

                                                            .byId("bijlageT")

                                                            .bindItems(

                                                                    "/"

                                                                            + this.aKeys[0]

                                                                            + "/Attachments",

                                                                    sap.ui

                                                                            .getCore()

                                                                            .byId(

                                                                                    'bijlagenTemplate'));

                                      

                                                    if (this.aKeys.length > 1) {

                                                        sap.ui.getCore().byId(

                                                                'masterSelect')

                                                                .setEnabled(

                                                                        true);

                                                    }

                                                }

                                            }

                                        });

Thanks!

RW

Answers (1)

Answers (1)

juancarlosorta
Participant
0 Kudos

Hi Robbe ,the event What I know is the onchange event.

Example here: https://sapui5.netweaver.ondemand.com/sdk/explored.html#/entity/sap.m.Select/events

view.xml:

<Select id="mySelect" change="onselectchange" selectedKey="...........>

controller.js:

onselectchange: function(oEvent){

this.getView().byId("mySelect").getSelectedKey();

....

//Binding

},


This event is only triggered when the value of the select is changed. You can binding element default, and binding again when event is triggered (select another key).


Remember, if the user does not change the value of the select, the event does not launch


Bye.

Former Member
0 Kudos

Hi,

Thanks but I already knew that. I'm searching for an event when the items are loaded, not when an item is selected.

When everything is loaded the selected key will be the key of the first item, aldo I actually never selected an item...

I fixed it with the setTimeout() function, but that's only temporary. I'm searching for a clean solution.

Regards,

RW

PMarti
Active Participant
0 Kudos

Hi Robbe, I show you an example to do that, as you say setTimeout() is a bad solution.

sap.m.Select have a private method which is fired for update items of bind. The solution is override this method and add your own logic.

Example: JS Bin - Example

I hope that it help you

Regards,

Pau

Former Member
0 Kudos

Hi Pau,

I tested your solution, but It's not working (async...).

Thanks anyways,

Robbe