cancel
Showing results for 
Search instead for 
Did you mean: 
Subscribe

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

0 Likes
View Entire Topic
saivellanki
Active Contributor
0 Likes

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.

Former Member
0 Likes

Yes, fileid it is a user input STRING value merged with a timestamp casted to a string too.

Anyway I have double checked this value and it is coherent with the oData service query input accepted.

Regards,

Claudia

saivellanki
Active Contributor
0 Likes

Hi Claudia,


After when you get response in the form of JSON, you have to handle some logic.

Please check this sample - http://embed.plnkr.co/te0BbGhEm7srVYn1UgEb/preview

1. I used some what a similar model structure.

2. First time, when the page is loaded I have hard-coded the file id to 'carriersmall.xml20150917135454' which will fetch me the data for that file and bind to the table. 

3. Now, there is file id text field placed below the table, you can try giving any of the below values and hit enter. The table data will get updated with respect to fileID.


carriersmall.xml20160917135455

carriersmall.xml20140917135456

I am using the same master model which has all the data, just I'm filtering on the file id and updating the table model.


Is this what you're expecting (or) is it different?


Regards,

Sai Vellanki.

Former Member
0 Likes

Hi Sai,

Yes, the example you provided is very similar to what I expect to get on my page
except for fileId column which I do not need to show into table.

So how can I bind correctly table rows to get data cells displayed as in your code ?

Regards,
Claudia

saivellanki
Active Contributor
0 Likes

Claudia,

Check the code here - http://plnkr.co/edit/te0BbGhEm7srVYn1UgEb?p=info

Let me know if you have any doubts.

Regards,

Sai Vellanki.

Former Member
0 Likes

Hi Sai,

Your solution is well-done but in my case I have an expanded entity set
so I am still not able to get data displayed into table rows.

Anyway, after I analyzed your code I do not understand the following line

sap.ui.getCore().getModel().setProperty("/modelData/masterData",aData.d.results);

Where does the 'masterData' path is coming from ?
I am not able to see this within the model located into the aData variable.

Regards,
Claudia

saivellanki
Active Contributor
0 Likes

Hi Claudia,

I hope you're storing the data response into a JSON model.

Can you alert the response and paste the data model here, I mean to say like this -


var oModel = sap.ui.getCore().getModel().getProperty("/d/results/1");

alert(JSON.stingify(oModel));      //Alerts the Header data

var oPositionModel = sap.ui.getCore().getModel().getProperty("/d/results/1/toPosition/results");

alert(JSON.stringify(oPositionModel));     //Alerts the Item Data

Regards,

Sai Vellanki.

Former Member
0 Likes

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 ?