Skip to Content
avatar image
Former Member

How to use formatter in a table??

Hi experts,

I want to make a field in a table coloured, So please guide me how to use formatter for a table field?

Piece of code that I have used for list formatter is like:

   firstStatus: [               {       text:"{DeliveryStatus}",    state:{    path:"DeliveryStatus",    formatter: function(id)                   {                   if(id == "Shipped")                   {                   return "Success"                   }                   if(id  == "Not Shipped")                   {                   return "Error"                   }                   if(id == "In Process")                   {                   return "Warning"                   }                   }}}    ]                              

});

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Oct 26, 2015 at 06:37 AM

    Hi,

    if you need conditonally format SAPUI5 table you can refer this link,

    Coloring Table Cells Conditionally in SAP UI5

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 26, 2015 at 06:45 AM

    var oControl = new sap.ui.commons.TextView().bindProperty("text", "bindpath",function(cellValue){ 

              switch(cellValue){ 

                        case 'D1': 

                                  backgroundColor = 'red'; 

                                  break; 

                        case 'D2': 

                                  backgroundColor = 'blue'; 

                                  break;  

                        case 'D3': 

                                  backgroundColor = 'yellow'; 

                                  break; 

                        default: 

                                  backgroundColor = 'white'; 

              } 

              cellId = this.getId();  

              $("#"+cellId).parent().parent().css("background-color",backgroundColor); 

              return cellValue; 

    }); 

    var oColumn = new sap.ui.table.Column({label: new sap.ui.commons.Label({text: "Columnhead1"}), template: oControl}); 

    oTable.addColumn(oColumn);

    Working example at  Color table cells depending on value of entry in row

    where the color of the cells are changing based on male(m) or female(f) indicator in the JSON

    Add comment
    10|10000 characters needed characters exceeded