Skip to Content

How to access a control with dynamic id

A control with dynamic id, for example “__component0—––Table1”, which changes in runtime and therefore this control cannot be accessed by fynction byId, can be however accessed in following way:

if for example there is the view with the table:

   <SearchField liveChange="onSearch"/>

then in the controller of this view ( this table can be accessed by following statement:

var oTable = this.getView().getContent()[1];

or in other controller this table can be accessed by calling corresponding function of this controller:

expandTable: function () {
var oTable = this.getView().getContent()[1];

See How to call function of one controller from another controller for more details.

You must be Logged on to comment or reply to a post.
    • I didn't say that byId not working, i said that control cannot be acessed by this function, because i cannot use this function for searching by id when id changes.

        • Exactly! As you can see above, the id "Table1" is assigned to TreeTable control, but this control cannot be found by sap.ui.getCore().byId("Table1"), because, as it also written above, in runtime id of this control is not "Table1", but "" (and in another view this control has another id):

          "it's not actually possible to have stable IDs for controls in bound aggregations"

          See SAPUI5 SDK - Demo Kit for more details.