Skip to Content
avatar image
Former Member

SAPUI5 : Currency formatting JS View List

Hi,

I am using a list within my Java Script view. I wish to prefix the currency symbol to the number(Price). I have come across examples in XML but I could not find any example with JavaScript.

I tried using the following, but does not work, and gives me an Syntax error in the Web IDE.

new sap.m.List("List", {
	items: {
		path: "ES5>/ProductCollection",
		template: new sap.m.ObjectListItem("ProdList",
			{
				title:"{ES5>ProductName}",
				intro:"{ES5>ProductCategory}",
				number:"{parts:[{path:'ES5>UnitPrice'}, 
						{path:'ES5>CurrencyCode'}],
					type:'sap.ui.model.type.Currency',
					formatOptions:{showMeasure:false}
					}",
				numberUnit: "{ES5>CurrencyCode}",
				type: sap.m.ListType.Active,
				press: [oController.onSelProd, oController]
			})
		}
	});

Here ES5 is the model referring to the GWDEMO oData service.

Please help me in identifying what is missing or what I am doing wrong here.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Apr 02 at 03:12 PM

    Check the example at

    https://sapui5.hana.ondemand.com/#/sample/sap.ui.core.sample.TypeCurrency/preview

    I would imagine you may be getting an error on trying to set your CurrencyCode, which I would assume is a string, to the type Currency, which is expecting a number. In the future, it would be helpful to include any errors you are seeing.

    Regards,

    Jamie

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Jamie,

      I apologize for a delayed response, as I was caught up with my Project deliverables.

      Thanks for replying and the solution provided by you exactly answers my requirement.

      Regards,

      Chetan Mishra

  • Apr 03 at 02:41 PM

    This is a copy&paste solution for you (or run it live on jsbin, which uses dependency injection as well):

    var oList = new sap.m.List("List", {
        items : {
            path: "ES5>/ProductCollection",
            template: new sap.m.ObjectListItem("ProdList", {
                title:"{ES5>ProductName}",
                intro:"{ES5>ProductCategory}",
                number: {
                    parts:[ {path:"ES5>UnitPrice"}, {path: "ES5>CurrencyCode"} ],
                    type: new sap.ui.model.type.Currency({
                        showMeasure: false
                    }),
                },
                numberUnit: "{ES5>CurrencyCode}",
                type: sap.m.ListType.Active,
                press: [oController.onSelProd, oController]
            })
        }
    });
    //...
    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Former Member,

      Thanks for replying, the following piece of code suggested by Jamie works for my requirements:

      number:"{parts:[{path:'ES5>UnitPrice'}, 
      						{path:'ES5>CurrencyCode'}],
      					type:'sap.ui.model.type.Currency',
      					formatOptions:{showMeasure: true, currencyCode: false}
      					}",