UI5 – Cleaning off Leading Zeros

Home / Blog / UI5 – Cleaning off Leading Zeros

Well, I’m back in UI5 world lately, and my hurdle today was to get rid of a bunch of leading zeros from my table worklist.  I wanted a way to clean all my text records within the table.  With a little help from google, here’s what I found.

I created a formatter function:

leadZero : function (sValue) {
sValue = sValue.replace(/^0+/, “”);
return sValue;
}

I’m no expert, but the code inside of the replace statement works great 🙂

then, I called it within my addcell method.

var txtNAME = new sap.m.Text(Field, {
text: {
path: Field,
formatter: formatter.leadZero
}
});
colItems.addCell(txtNAME);

Notice, in my example: path does NOT have the curly brackets {}

Hope this might help,

As always, thanks for reading and don't forget to check out our SAP Service Management Products at my other company JaveLLin Solutions,
Mike

Leave a Reply

Your email address will not be published. Required fields are marked *