Search code examples
xmlbindingnestedfilteringsapui5

SAPUI5 : Is it possible to do a nested binding in a binding filter


I have a xml view with a TabFilterBar that includes two IconTabFilter. The property count for the first IconTabFilter is bound like this :

count="{/TestDataSet(Systemid='XYZ', Version='1.0')/Value1}"

And for the second IconTabFilter:

count="{/TestDataSet(Systemid='XYZ', Version='1.0')/Value2}"

Inside the binding I do a filtering. For now the filter values for Systemid and Version are just hard coded.

I want now to read the filter values out of a model.

For that I created a JSON Model filterModel. In this model I have a property for Systemid and one for Version. It holds the actual value for this property.

I am able to use and read the new model with it's properties in the XML view:

{filterModel>systemid}
{filterModel>version}

I tried know to include that in my binding of the IconTabFilter. It looks like this:

<IconTabBar id="TabFilterBar">
  <items>
    <IconTabFilter id="TabFilterOne" icon="sap-icon://database" iconColor="Neutral" text="{i18n>TabFilterOne}" count="{/TestDataSet(Systemid='{filterModel>systemid}', Version='{filterModel>version}')/Value1}"/>
    <IconTabFilter id="TabFilterTwo" icon="sap-icon://check-availability" iconColor="Neutral" text="{i18n>TabFilterTwo}" count="{/TestDataSet(Systemid='{filterModel>systemid}', Version='{filterModel>version}')/Value2}"/>
  </items>

But this is not working.

How can I archieve to use a binding nested in a filter of a binding?


Solution

  • I don’t think it’s possible to actually nest the props. I would do it the following way:

    <IconTabBar id="TabFilterBar" binding="{/TestDataSet(Systemid='XYZ', Version='1.0')}">
      <items>
        <IconTabFilter count="{Value1}" id="TabFilterOne" icon="sap-icon://database" iconColor="Neutral" text="{i18n>TabFilterOne}"/>
        <IconTabFilter count="{Value2}" id="TabFilterTwo" icon="sap-icon://check-availability" iconColor="Neutral" text="{i18n>TabFilterTwo}"/>
      </items>
    </IconTabBar>
    

    And update binding of the IconTabBar whenever your filter is changed from within the controller. Something like

      this.getView().byId("TabFilterBar").bindObject("/TestDataSet(Systemid='ABC', Version='47.11')")
    

    should do it