Skip to Content
Author's profile photo Former Member

How to access a control in fragment

Fragment, instead of view, do not have any controller and, therefore, in fragment a control, which cannot be accessed with the help of function byId because fragment is used in many places and id of this control cannot be “hard-coded” in xml, can be however accessed in following way:

if for example there is the fragment Table1.fragment.xml with the table:


<core:FragmentDefinition
  xmlns="sap.m"
  xmlns:core="sap.ui.core"
  xmlns:layout="sap.ui.layout"
  xmlns:table="sap.ui.table"
>
  <table:Table
    rows="{/root}"
  >
    <table:columns>
      ...
    </table:columns>
  </table:Table>
</core:FragmentDefinition>

which in turn is a part of the fragment Dialog.fragment.xml for pop-up Dialog:


<core:FragmentDefinition
  xmlns="sap.m"
  xmlns:core="sap.ui.core"
  xmlns:layout="sap.ui.layout"
>
  <Dialog draggable="true" class="sapUiPopupWithPadding">
    <VBox width="1024px">
      <IconTabBar
        expanded="true"
        expandable="false"
        class="iconTabBarnarrow">
        <items>
          <IconTabFilter text="Table1">
            <core:Fragment fragmentName="Table1" type="XML" />
          </IconTabFilter>
        </items>
      </IconTabBar>
    </VBox>
    <beginButton>
      <Button text="Close" press="onDialogClose"/>
    </beginButton>
  </Dialog>
</core:FragmentDefinition>

then this table can be accessed (for example, for calling function rerender) by following statements:


onDialogOpen: function(oEvent) {
  if (! this._oDialog) {
    this._oDialog = sap.ui.xmlfragment("Dialog", this);
    this.getView().addDependent(this._oDialog);
  }
  this._oDialog.setTitle("Dialog"));
  jQuery.sap.delayedCall(0, this, function () {
    this._oDialog.open();
    this._oDialog.getContent()[0].getItems()[0].getItems()[0].getContent()[0].rerender();
  });
}

Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hi,

      I think you should read this chapter... OpenUI5 SDK - Demo Kit

      Kind regards,

      RW