cancel
Showing results for 
Search instead for 
Did you mean: 

UI5 path to parent property

Former Member
0 Kudos
3,117

Hi,

I have an application which has Header (from oData) binded to screen, table with Items with relative path "items". All of that is done in XML file, how can I get there a path in item level to parent? I mean I want to bind for item some property from header

Accepted Solutions (1)

Accepted Solutions (1)

former_member227918
Active Contributor
0 Kudos

directly its not possible.

you need to create a named model and set this model to view/core, and then you will able to use header data using model name, something like below:

var oModel = new sap.ui.model.json.JSONModel(your header data here);    
this.getView().setModel(oModel,"HeaderDataModel");
// and then you can use header data anywhere in the view using "HeaderDataModel"

<button enabled ="{HeaderDataModel>/HeaderAttr2}">

Hope this will help you.

Regards,

Akhilesh

Answers (4)

Answers (4)

htammen
Active Contributor

Just set the binding path to the header property.

Here is an example in which I show a property even from another model just by defining the respective path

<m:Table id="idProductsTable" inset="false" items="{pdfs>/pdfs}">
  <m:columns>
    <m:Column>
      <m:Text text="note"/>
    </m:Column>
    <m:Column minScreenWidth="Tablet" demandPopin="true">
      <m:Text text="mobile phone"/>
    </m:Column>
  </m:columns>
  <m:items>
    <m:ColumnListItem>
      <m:cells>
        <m:ObjectIdentifier text="{pdfs>note}"/>
        <m:Link text="{Phone/Mobile}" target="_blank" href="{pdfs>url}"/>
      </m:cells>
    </m:ColumnListItem>
  </m:items>
</m:Table>

In this example I use even a property from another model inside my table. The table items is bound to "pdfs>/pdfs" whereas the mobile phone column is bound to "/Phone/Mobile" of the views default model.

Note: It's always easier to understand your problem if you add some sample coding to your questions.

Regards Helmut

Former Member
0 Kudos

Here is the situation:

Controller before rendering binds Header to view. I have in table relation in items as relative path "{items}" (navigation property from header to items). So now I would like to have access in item level to Header properties.

<label id="label1" value="{HeaderAttr1}>

<Table items="{items}>
...
<items>
...
<button enabled ="{HeaderAttr2}">

HeaderAttr2 - doesn't work, just like: /../HeaderAttr2, ../HeaderAttr2

My problem in comparing to Helmut code is that my Header is binded to a view by controller, so HeaderAttr1 works in label, but I don't know how to access data from item to those attributes.
I'm looking for nice, clear way.

karthikarjun
Active Contributor
0 Kudos

Hi Adam- You can follow the below steps.

  1. Bind data from odata to json model.
  2. Use bind property to display required entity
  3. ex: sap.m.Text().bindproperty("text", "JSONModel>/UserCollection/UserId(1)").

Regards,

Karthik A

saivellanki
Active Contributor
0 Kudos

Hi Adam,

Did you check this thread? OData 'expand' parameters

Regards,

Sai.