Skip to Content
author's profile photo Former Member
Former Member

oData collection not binding to data table rows

Hi experts,

I am developing a UI5 web application which consumes oData collections.
One of these oData collection is fetched using get_expanded_entityset method which I implemented in my oData service

The get_expanded_entityset method returns both header and line items in the form of a collection of items [in my case it is called 'toPosition' navigation property]

Now I have a data table which is binded to that oData method but I am not able to get the single line items data displayed into each cell.

This is the data bind code I use

var oModelCarrier = new sap.ui.model.odata.ODataModel('/sap/opu/odata/sap/Z_COLL_PORTAL_SRV',{json:true});

var tableCarrier = sap.ui.getCore().byId("carrierInvoiceSub-carrierSubmission--carrierTable");

tableCarrier.setModel(oModelCarrier);

oModelCarrier.setCountSupported(false);

tableCarrier.bindRows( {path: '/fileRepositorySet',

filters : [ new sap.ui.model.Filter("fileId", sap.ui.model.FilterOperator.EQ, fileid) ],

parameters : {expand: 'toPosition'}

});

and this is the table view part

<table:Table id="carrierTable" enableGrouping="true" enableSorting="true">

<table:title><Textview text="Carrier Shipments [Uploaded]"></Textview></table:title>

<table:columns>

<table:Column>

<Label text="Invoice Num."/>

<table:template>

<layout:VerticalLayout content="{toPosition/results}" xmlns:layout="sap.ui.layout">

<layout:content>

<TextView text = "{invoiceNumber}" />

</layout:content>

</layout:VerticalLayout>

</table:template>

</table:Column>

<table:Column>

<Label text="Container Type"/>

<table:template>

<layout:VerticalLayout content="{toPosition/results}" xmlns:layout="sap.ui.layout">

<layout:content>

<TextView text = "{containerType}" />

</layout:content>

</layout:VerticalLayout>

</table:template>

</table:Column>

</table:columns>

</table:Table>

and most important this is the oData response I get from my service calling get_expanded_entityset

can anyone help me how to get collection data displayed on table cells ?

it seems the response I get is correct containing all the data I need for my application [pls see attachment table_response.png ].

please be patient with me, I am learning oData / UI5 technology so I am not an expert

best regards,

claudia

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    Posted on Sep 23, 2015 at 05:24 PM

    Hi Claudia,

    Check this working sample, where I used your JSON response: JS Bin - Collaborative JavaScript Debugging


    Few points -

    1. I have added comments in the code, hope you will understand.

    2. Since you told me fileId is a user input, so the logic is handled such a way where the fileid is must to filter the item details.

    3. In text field control placed down the table, try to provide this fileId value carrierfile20150923174312, then the table data will get updated with respect to that fileId.

    Regards,

    Sai Vellanki.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 18, 2015 at 10:42 AM

    hi Claudia,

    if no errors in the developer tools console, can you try switching this line:

    var oModelCarrier = new sap.ui.model.odata.ODataModel('/sap/opu/odata/sap/Z_COLL_PORTAL_SRV',{json:true});

    to

    var oModelCarrier = new sap.ui.model.odata.ODataModel('/sap/opu/odata/sap/Z_COLL_PORTAL_SRV', true );

    hope this helps

    Sergio

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Sergio Guerrero

      Sergio,

      I am not able to view data even if I changed the items path for the data table.

      What do you mean in details with 'since it is a child of the header data, you may need to specify one more level deep in your code' ? Is it about some to add for the binding in the table for example

      1. <table:Table id="carrierTable" items="{path:'/d/results/1/toPosition/results'}">

      or something into the controller.js side

      2. tableCarrier.bindRows( {path: '/fileRepositorySet',

      filters : [ new sap.ui.model.Filter("fileId", sap.ui.model.FilterOperator.EQ, fileid) ],

      parameters : {expand: 'toPosition'}

      });

      Do you think in case of point 1. the path would be correct using '/d/results/1/toPosition/results' for the odata received for this scenario ?

      Regards,
      Claudia

  • Posted on Sep 21, 2015 at 07:27 AM

    Hi Claudia,

    Data that you wanted to bind to the table rows is present only in /toPosition/results (or) any other value is present in /d/results/0/.... etc? Since I can see Invoice number is also available in '/toPosition/results'.


    Regards,

    Sai Vellanki.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Sai,

      Data needed to bind table rows are not in /d/results/0/...
      This is the header for the structure and invoiceNumber is one field available both in header and items structure.


      I think the correct path should [but I am not sure] like this /d/results/1/toPosition/results .

      My concern is about if the path I pass is correct and how to fix to get rows displayed.

      Maybe also the bindRows(..) statement which I coded is not able to get the correct binding with data but I am able to see the response from the service with expected data [...]

      table_response.PNG (25.9 kB)
  • Posted on Sep 21, 2015 at 08:02 AM

    Hi Claudia,

    Also, tell me what value are you passing for 'fileid'. Is it a user input value?

    tableCarrier.bindRows( {path: '/fileRepositorySet',
            filters : [ new sap.ui.model.Filter("fileId", sap.ui.model.FilterOperator.EQ, fileid) ],
            parameters : {expand: 'toPosition'}
    });
    

    Regards,

    Sai Vellanki.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Sai Vellanki

      Hi Sai,

      Here is the data response I get.

      {"d":

      {"results":

      [

      "fileId":"carrierfile20150923174311",

      "recipientNumber":"recipient123",

      "invoiceNumber":"201510156836",

      "invoiceDate":"20150311",

      "invoiceCurrency":"EUR",

      "invoiceAmount":"256.77",

      "invoiceDueDate":"20151211",

      "accountNumber":"123123123",

      "countryCode":"IT",

      "taxId":"45347475756757",

      "toPosition":

      {"results":

      [

      "invoiceNumber":"201510156836","leadShipmentNumber":"1ZW19E460443751298","transactionDate":"20150216","trackingNumber":"1ZW19E460443751298","zone":"000","containerType":"PKG","quantity":"1","weight":"0.00 ","unitOfMeasure":"K","descriptionCode":"069","descriptionOfCharges":"Correzione dell'indirizzo WW Express Saver","currencyCode":"EUR","netAmount":"6.60 "},

      {

      "invoiceNumber":"201510156836","leadShipmentNumber":"1ZW19E460444937710","transactionDate":"20150219","trackingNumber":"1ZW19E460444937710","zone":"000","containerType":"PKG","quantity":"1","weight":"0.00 ","unitOfMeasure":"K","descriptionCode":"9","descriptionOfCharges":"","currencyCode":"EUR","netAmount":"0.00 "},

      "invoiceNumber":"201510156836","leadShipmentNumber":"1ZW19E460444937710","transactionDate":"20150219","trackingNumber":"1ZW19E460444937710","zone":"000","containerType":"PKG","quantity":"1","weight":"0.00 ","unitOfMeasure":"K","descriptionCode":"069","descriptionOfCharges":"Correzione dell'indirizzo WW Express Saver","currencyCode":"EUR","netAmount":"6.60 "},

      "invoiceNumber":"201510156836","leadShipmentNumber":"1ZW19E460443202747","transactionDate":"20150227","trackingNumber":"1ZW19E460443202747","zone":"000","containerType":"PKG","quantity":"1","weight":"0.00 ","unitOfMeasure":"K","descriptionCode":"9","descriptionOfCharges":"","currencyCode":"EUR","netAmount":"0.00 "},

      "invoiceNumber":"201510156836","leadShipmentNumber":"1ZW19E460443202747","transactionDate":"20150227","trackingNumber":"1ZW19E460443202747","zone":"000","containerType":"PKG","quantity":"1","weight":"0.00 ","unitOfMeasure":"K","descriptionCode":"069","descriptionOfCharges":"Correzione dell'indirizzo WW Express Saver","currencyCode":"EUR","netAmount":"6.60 "},

      "invoiceNumber":"201510156836","leadShipmentNumber":"1ZW19E460445313454","transactionDate":"20150302","trackingNumber":"1ZW19E460445313454","zone":"000","containerType":"PKG","quantity":"1","weight":"0.00 ","unitOfMeasure":"K","descriptionCode":"9","descriptionOfCharges":"","currencyCode":"EUR","netAmount":"0.00 "},

      "invoiceNumber":"201510156836","leadShipmentNumber":"1ZW19E460445313454","transactionDate":"20150302","trackingNumber":"1ZW19E460445313454","zone":"000","containerType":"PKG","quantity":"1","weight":"0.00 ","unitOfMeasure":"K","descriptionCode":"069","descriptionOfCharges":"Correzione dell'indirizzo WW Express Saver","currencyCode":"EUR","netAmount":"6.60 "},

      "invoiceNumber":"201510156836","leadShipmentNumber":"1ZW19E460445313454","transactionDate":"20150302","trackingNumber":"1ZW19E460445313454","zone":"000","containerType":"PKG","quantity":"1","weight":"0.00 ","unitOfMeasure":"K","descriptionCode":"9","descriptionOfCharges":"","currencyCode":"EUR","netAmount":"0.00 "}]

      }

      }

      ]

      }

      }

      Do you think this specific response would cause error if binded to table rows ?

  • Posted on Sep 23, 2015 at 04:10 PM

    Claudia,

    In your response, Can you please remove the URLs in ID (Since those are your internal URLs).

    Thanks for providing it. I will look into this and come back to you.


    Regards,

    Sai Vellanki.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thanks for the suggestion, Sai.
      I have deleted all the references to any URL in the JSON response.
      Now I try to code your solution to see if it works for my scenario.

      In the meantime many thanks for your support,

      Kind regards,

      Claudia

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.