cancel
Showing results for 
Search instead for 
Did you mean: 

Display sap.m.table cells font color dynamically based on other cells/columns comparison.

Former Member
0 Kudos

Hi,

I saw few examples to color the table cells using formatter function definition in columnlistitem.Please suggest / recommend sample code to read model data directly to validate and display colors of tablecells based on validations as column names also dynamic.

Regards,

Koti Reddy

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

as of now I tried to display colors dynamically for first column elements if cell content matches with some string but I font color is not changing.

Tried below code from onUpdateFinished method .

var items = sap.ui.getCore().byId("ViewId").byId("table").getItems();

      

        for (i = 0; i < items.length; i++) {

              var item = items[i];

              var obj = item.getBindingContext().getObject();

              if (obj.status === "Not Well") {

                  $(item.$().find('td')[0]).addStyleClass("columnStyle1");}

            

        }

from debugging , I was able to read all items and data as well but my CSS style is not adding to change font color of the first element.

.columnStyle0 {

  color: red;

}

.columnStyle1 {

  color: green;

}

Please let me know your recommendations on above procedure.

Regards,

Koti Reddy

former_member182862
Active Contributor
0 Kudos

HI Koti

Can it be like this

        for (i = 0; i < items.length; i++) {
              var item = items[i];
              var obj = item.getBindingContext().getObject();
              var $item = $(item.$().find('td')[0]);
              if (obj.status === "Not Well") {
                  $item.addClass("columnStyle1");
              } else {
                  $item.addClass("columnStyle0");
              }
        }

-D

Former Member
0 Kudos

Hi Dennis,

Your suggested code looks correct but JQuery didn't work in my code. Do I need to define any syntax in index.html or somewhere else to work with JQuery?

Regards,

Koti Reddy

former_member182862
Active Contributor
0 Kudos

Hi Koti

Jquery should work, there must be some error in the code. What error do you got?

-D

Former Member
0 Kudos

There were no errors.I think JQuery is also working.Might be some caching issue.

Answers (1)

Answers (1)

kai2015
Contributor
0 Kudos

This is what you want or?