cancel
Showing results for 
Search instead for 
Did you mean: 

To remove leading zero using expression binding in XML View

Former Member
0 Kudos

Hello experts,

I am very new to the Fiori. I wanted to know the code for removing the leading zeros in the line item of the table in XML view.
I know it can be achieved using JS formatter function, but would like to achieve using expression binding as I am not much familiar of this concept..

For example

00005 -> 5

00001 -> 1

Regards,

Salil B

Accepted Solutions (1)

Accepted Solutions (1)

saurabh_vakil
Active Contributor
0 Kudos

The field which contains the value with the leading zeroes - if you are sure that this field will always contain a string value (for e.g. 00001234) the just call the parseInt() function and pass the value to this function as parseInt('00001234'); the result will be 1234.

Former Member
0 Kudos

Hello Saurabh,

I am aware of this as mentioned using Javascript as mentioned below, but wanted to achieve it using the XML expression binding. Let me know if you are aware of how to do it without going with JS.

stripLeadingZeros : function(v) {

            if (typeof v === "string") {

                  return parseInt(v, 10)

            }

            return v

      },

Regards,

Salil B

saurabh_vakil
Active Contributor
0 Kudos

You can use something like below:


<Text  text"{= parseFloat(${ExtendedPrice}) }" />

So if the model field ExtendedPrice holds the value '0001234' the above will convert it to '1234'.

Former Member
0 Kudos

Thanks Saurav, it worked like this way.

Regards,

Salil B

Answers (1)

Answers (1)

sascha_roehm
Explorer

Achieving this in XML view you can use a constraint:

<ObjectIdentifier text = "{path : 'CUSTOMER_ID', type : 'sap.ui.model.odata.type.String', constraints : {isDigitSequence : true, maxLength : 10 }}" title="{NAME}"/>