Search code examples
odatasapui5

How use multiples properties on "expand" parameter in List component [sapui]


I have a sap.m.List component where invoke a list of OData objects. This object have others object inside it. For this reason, I use expand parameter for accessing to propertis of intern object. But when I put multiples objects on "expand" parameter, list component doesn't work:

This way doesn't work:

<List id="lstRequest" headerText="Custom Content"  
      items="{
                path: '/Requests',
                parameters: {
                   expand: ['RequestTypeDetails', 'UsersDetails']
                }
              }" 
>
    <StandardListItem
        title="{RequestTypeDetails/RequestType2} - {RequestCode}"
        description="{TotalAdvance}"
        icon="sap-icon://request"
        iconDensityAware="false"
        iconInset="false"
        type="Navigation"
        press="onSelectApprovation"  />
</List>

This way works:

<List id="lstRequest" headerText="Custom Content"  
      items="{
                path: '/Requests',
                parameters: {
                   expand: 'RequestTypeDetails'
                }
              }" 
>
    <StandardListItem
        title="{RequestTypeDetails/RequestType2} - {RequestCode}"
        description="{TotalAdvance}"
        icon="sap-icon://request"
        iconDensityAware="false"
        iconInset="false"
        type="Navigation"
        press="onSelectApprovation"  />
</List>

I don't know how especific when I need to use multiples objets on "expand" parameter.

Thanks for your help!

UPDATE 1

The solution give for @Nabi looks working...But I'm not secure because I call elements of list on a detail page.

I create a JSONModel object with element of list and then invoke this object on detail page:

var itemJSONModel = new JSONModel(itemObject, false);

this.setModel(itemJSONModel, "detailView");

But in my detail page I can't see value of UsersDetails properties (Users is an object inside item object. UsersDeails is the name of NavigationProperty):

<Input fieldGroupIds="datos_suscripcion" value="{detailView>/UsersDetails/UserName}"
                       placeholder="Usuario..." 
                       id="inUsuario"/>

EDIT 2

This is OData model of item object:

<EntityType Name="Request">
<Key>
<PropertyRef Name="Id"/>
</Key>
<Property Name="AirTicketBuyer" Type="Edm.String" Nullable="true" MaxLength="50"/>
<Property Name="AirTicketBuyerEmail" Type="Edm.String" Nullable="true" MaxLength="50"/>
<Property Name="BusTicketBuyer" Type="Edm.String" Nullable="true" MaxLength="50"/>
<Property Name="BusTicketBuyerEmail" Type="Edm.String" Nullable="true" MaxLength="50"/>
<Property Name="CostCenter" Type="Edm.Int32" Nullable="false"/>
<Property Name="Created" Type="Edm.DateTime" Nullable="false"/>
<Property Name="Currency" Type="Edm.Int32" Nullable="false"/>
<Property Name="Department" Type="Edm.Int32" Nullable="false"/>
<Property Name="DepartureDate" Type="Edm.DateTime" Nullable="false"/>
<Property Name="DepartureRoute" Type="Edm.String" Nullable="false" MaxLength="100"/>
<Property Name="DepartureTransportationType" Type="Edm.String" Nullable="false" MaxLength="1"/>
<Property Name="Destination" Type="Edm.String" Nullable="false" MaxLength="128"/>
<Property Name="DestinationType" Type="Edm.String" Nullable="false" MaxLength="1"/>
<Property Name="ExpirationDate" Type="Edm.DateTime" Nullable="false"/>
<Property Name="Id" Type="Edm.Int32" Nullable="false"/>
<Property Name="IdApplicant" Type="Edm.Int32" Nullable="true"/>
<Property Name="IdCompany" Type="Edm.Int32" Nullable="false"/>
<Property Name="IdUser" Type="Edm.Int32" Nullable="false"/>
<Property Name="Reason" Type="Edm.String" Nullable="false" MaxLength="200"/>
<Property Name="RequestCode" Type="Edm.String" Nullable="false" MaxLength="15"/>
<Property Name="RequestFatherId" Type="Edm.Int32" Nullable="true"/>
<Property Name="RequestStatus" Type="Edm.Int32" Nullable="false"/>
<Property Name="RequestType" Type="Edm.Int32" Nullable="false"/>
<Property Name="ReturnDate" Type="Edm.DateTime" Nullable="false"/>
<Property Name="ReturnRoute" Type="Edm.String" Nullable="false" MaxLength="100"/>
<Property Name="ReturnTransportationType" Type="Edm.String" Nullable="false" MaxLength="1"/>
<Property Name="SapCodeApplicant" Type="Edm.String" Nullable="true" MaxLength="6"/>
<Property Name="SapCodeUser" Type="Edm.String" Nullable="true" MaxLength="6"/>
<Property Name="StartFlowDate" Type="Edm.DateTime" Nullable="false"/>
<Property Name="TipoReq" Type="Edm.String" Nullable="true" MaxLength="2"/>
<Property Name="TotalAdvance" Type="Edm.Decimal" Nullable="false" Precision="12" Scale="2"/>
<NavigationProperty Name="ApprovalsRequestDetails" Relationship="rva-persistence.ApprovalsRequest_Request_Many_ZeroToOne0" FromRole="Request" ToRole="ApprovalsRequest"/>
<NavigationProperty Name="CostCenterDetails" Relationship="rva-persistence.Request_CostCenter_Many_ZeroToOne0" FromRole="Request" ToRole="CostCenter"/>
<NavigationProperty Name="CurrencyDetails" Relationship="rva-persistence.Currency_Request_One_Many0" FromRole="Request" ToRole="Currency"/>
<NavigationProperty Name="DepartmentDetails" Relationship="rva-persistence.Department_Request_One_Many0" FromRole="Request" ToRole="Department"/>
<NavigationProperty Name="ExpenseAdvanceDetails" Relationship="rva-persistence.ExpenseAdvance_Request_Many_ZeroToOne0" FromRole="Request" ToRole="ExpenseAdvance"/>
<NavigationProperty Name="CompanyDetails" Relationship="rva-persistence.Company_Request_One_Many0" FromRole="Request" ToRole="Company"/>
<NavigationProperty Name="UsersDetails" Relationship="rva-persistence.Users_Request_One_Many0" FromRole="Request" ToRole="Users"/>
<NavigationProperty Name="PassengerDetails" Relationship="rva-persistence.Passenger_Request_Many_ZeroToOne0" FromRole="Request" ToRole="Passenger"/>
<NavigationProperty Name="ReportDocumentDetails" Relationship="rva-persistence.ReportDocument_Request_Many_ZeroToOne0" FromRole="Request" ToRole="ReportDocument"/>
<NavigationProperty Name="RequestStatusDetails" Relationship="rva-persistence.Request_RequestStatus_Many_ZeroToOne0" FromRole="Request" ToRole="RequestStatus"/>
<NavigationProperty Name="RequestTypeDetails" Relationship="rva-persistence.RequestType_Request_One_Many0" FromRole="Request" ToRole="RequestType"/>
</EntityType>

Solution

  • Use a simple comma separated string:

    <List 
        id="lstRequest"
        headerText="Custom Content"  
        items="{
            path: '/Requests',
            parameters: {
                expand: 'RequestTypeDetails,UsersDetails'
            }
        }" 
    >