Skip to Content
avatar image
Former Member

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

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

Add comment
10|10000 characters needed characters exceeded

  • 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
  • Get RSS Feed

3 Answers

  • Best Answer
    Dec 21, 2016 at 05:30 PM
     template:newsap.ui.commons.TextField({value:"1:{RATE}"})

    give it a try

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 22, 2016 at 08:20 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 29, 2016 at 02:35 PM

    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}"})
    Add comment
    10|10000 characters needed characters exceeded