cancel
Showing results for 
Search instead for 
Did you mean: 

How to use formatter in a table??

Former Member
0 Kudos

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"
                  }
                  }}}
   ]
     
     
           
     

});

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

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

Former Member
0 Kudos

Thanks!!!

Answers (1)

Answers (1)

vijay_kumar49
Active Contributor
0 Kudos

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