cancel
Showing results for 
Search instead for 
Did you mean: 

How to append a constant value to a SAPUI5 table's column value

Former Member
0 Kudos
631

Hi all,

I am trying to append constant "1:" to one of the table column values. My table column is :

var oTable = new sap.ui.table.Table({
    selectionMode : sap.ui.table.SelectionMode.Single,    selectionBehavior: sap.ui.table.SelectionBehavior.Row });    oTable.addColumn(new sap.ui.table.Column({
        label: new sap.ui.commons.Label({text: "Rate"}),
        template: new sap.ui.commons.TextField({value: "{RATE}"})
      }));

Now on that above column i am trying to add constant as "1:". But if i try like as shown below, i don't get the desired result.

oTable.addColumn(new sap.ui.table.Column({

            label: new sap.ui.commons.Label({text: "Rate"}),

            template: new sap.ui.commons.TextField({value: "1:"+"{RATE}"})

          }));

I intend to do this change in a clean way if possible? How can i achieve this? Looking forward to your solutions. Thanks in advance

kedarT
Active Contributor
0 Kudos

Hi Amit,

How about using formatter and to accomplish this something like this:

oTable.addColumn(newsap.ui.table.Column({

            label:newsap.ui.commons.Label({text:"Rate"}),

            template:newsap.ui.commons.TextField({value: 

                                                { path: "RATE",formatter: function(val){ return "1" + val;}}})}));


Hope this helps

Accepted Solutions (1)

Accepted Solutions (1)

junwu
Active Contributor
 template:newsap.ui.commons.TextField({value:"1:{RATE}"})

give it a try

Answers (2)

Answers (2)

former_member185029
Active Contributor
0 Kudos

Create additional attribute in your model and bind that model to the elements.

myModel[0].NewRate = "1:"+myModel[0].Rate;

and then the mapping will look something like

 template: new sap.ui.commons.TextField({value: "{NewRate}"})
SergioG_TX
Active Contributor
0 Kudos

i second Jun Wu approach.. normally when you use data binding you would use ...

"{YOUR_PROPERTY}" unless you have a named model

"{NAMED_MODEL>/YOUR_PROPERTY}" and you can use constant values next to it as Jun Wu showed before