cancel
Showing results for 
Search instead for 
Did you mean: 

Sapui5 Expression Binding - get a property of the last position of an array

juancarlosorta
Participant

Hello all. I have a problem with a binding expression in a column of a table (sap.ui.table).

Currently my column points to a property of the first position of an array (results/0/cust_Date😞

<Column>
   <m:Label text="Date"/>
  <template>
      <m:Text text="{path:'externalCodeOfcust_PRLRMNav/results/0/cust_Date', formatter:'.formatter.convertDate'}" wrapping="false"/>
  </template>
</Column>

but now I want to point to a property of the last position of the array (results/...results.length-1/cust_Date).

For this I have tried many combinations of this type:

<Column>
  <m:Label text="Date"/>
<template>
    <m:Text text="{path:'externalCodeOfcust_PRLRMNav/results/{= ${externalCodeOfcust_PRLRMNav/results}.length-1}/cust_Date', formatter:'.formatter.convertDate'}" wrapping="false"/>
</template>
</Column> 

With this binding expression:

{= ${externalCodeOfcust_PRLRMNav/results}.length-1}

I can get the length of the array and then with -1 to know the last position, but when I combine it with the rest of the path to get the cust_Date property, it doesn´t work. Do you know how I could do it?

Thanks in advance. Best Regards

Accepted Solutions (1)

Accepted Solutions (1)

sergei-u-niq
Active Contributor

Well, if that works:

{= ${externalCodeOfcust_PRLRMNav/results}.length-1}

then this should also work:

{= ${externalCodeOfcust_PRLRMNav/results}[   ${externalCodeOfcust_PRLRMNav/results}.length-1   ].custDate.split(...)...  }

Answers (2)

Answers (2)

juancarlosorta
Participant
0 Kudos

Thank you very much Sergei.

That has worked for me with that binding:

<m:Text text="{= ${externalCodeOfcust_PRLRMNav/results}[ ${externalCodeOfcust_PRLRMNav/results}.length-1 ].cust_Date'}" wrapping="false"/>


, but it doesn't work for me with a binding with path (for formatting):

<m:Text text="{path:'= ${externalCodeOfcust_PRLRMNav/results}[ ${externalCodeOfcust_PRLRMNav/results}.length-1 ].cust_Date', formatter:'.formatter.convertDate'}" wrapping="false"/>


Would you know why?

sergei-u-niq
Active Contributor
0 Kudos

you either use expression binding, or you use a formatter. you could see it that way: expression binding is an in-place-formatter.

juancarlosorta
Participant
0 Kudos

Finally, I have chosen to pass the array to the formatter and process it there.

<Column filterProperty="externalCodeOfcust_PRLRMNav/results/0/cust_Date"
sortProperty="externalCodeOfcust_PRLRMNav/results/0/cust_Date">
   <m:Label text="Date"/>
   <template>
      <m:Text text="{path:'externalCodeOfcust_PRLRMNav/results/', formatter:'.formatter.convertDateArray'}" wrapping="false"/>
</template>
formatter.js

convertDateArray: function (array) {
  if (array.length>0){
     var date = new Date(parseInt(array[array.length-1].cust_Date.split("/Date(")[1].split(")/")[0]))......
.....

But I still want to know how to do it through expression binding, since for example now I want to put in the column a filterProperty or a sortProperty and I would not know how to get this last position of the array for filter or sort with it.

Thanks