cancel
Showing results for 
Search instead for 
Did you mean: 

enhance table before display

RyabovAlex
Advisor
Advisor
0 Kudos

hello everyone,

I'm trying to enhance cell colors depending on the content of the cell.

I'm consuming oData service from SAP backend.

this is the table:


var oTable = new sap.ui.table.Table({

  id: "OverviewTable",

  width : "100%",

  rowHeight : 20,

  title : "",

});

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

  label : new sap.ui.commons.Label({text : "Группа компаний""}),

  template : new sap.ui.commons.TextView().bindProperty("text","SENDER_NUM"),

   sortProperty : "SENDER_NUM",

   filterProperty : "SENDER_NUM",

  }));

oTable.bindRows("/DASHBOARDSet");

return oTable;

So, I'm passing values to table by .bindRows(); and field values: SENDER_NUM

The thing is that I'm trying to change cell color depending what value the SENDER_NUM has.

Where can I fetch the results?

As onInit, onBeforeRendering, and even after return.oTable there are no values yet in the table.

Where can I fetch the filled in value in the table?

Thank you.

Accepted Solutions (1)

Accepted Solutions (1)

RyabovAlex
Advisor
Advisor
0 Kudos

the correct answer is mentioned in this post:


template: new sap.ui.commons.TextView().bindProperty("text", "amount", function(cellValue) { 

               // remove styles else it will overwrite  

                this.removeStyleClass('green'); 

                this.removeStyleClass('yellow'); 

                this.removeStyleClass('red'); 

                // Set style Conditionally 

                if (cellValue >= 1500) { 

                    this.addStyleClass('green'); 

                } else if(cellValue < 1500 && cellValue > 1000) { 

                    this.addStyleClass('yellow'); 

                } else

                this.addStyleClass('red');              

                } 

                return cellValue; 

            }),   

         



former_member182372
Active Contributor
0 Kudos

hm, interesting, this in formatter references to the UI control, i would never thought 😉

Answers (1)

Answers (1)

former_member182372
Active Contributor
0 Kudos

Alex,


I would define a delegate on a control



var gruppaCompaniyControl = new sap.ui.commons.TextView().bindProperty("text","SENDER_NUM");


gruppaCompaniyControl.addDelegate({

  onAfterRendering: function () {

  var _value = this.getText();

  if(_value==="Клёвая комания")

  {

       this.addStyleClass("cool");

  }

}}, false, gruppaCompaniyControl, true);


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

  label : new sap.ui.commons.Label({text : "Группа компаний""}), 

  template : gruppaCompaniyControl, 

  sortProperty : "SENDER_NUM", 

  filterProperty : "SENDER_NUM", 

})); 



define your own CSS:

.cool {

  background-color: #ffdbdb;

}

RyabovAlex
Advisor
Advisor
0 Kudos

Hello Maksim, great help from you!

But it works 50% only.

I still can't get the value of field

On this step IF is not working:


var P8_template = new sap.ui.commons.TextView().bindProperty("text","P8_TOTAL"); 

  P8_template.addDelegate({ 

   onAfterRendering: function () { 

   var _value = this.getText(); 

   if(_value == "Name1")  { 

        this.addStyleClass("cool"); 

   } 

  }}, false, P8_template, true); 

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

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

  template: P8_template,

  sortProperty : "P8_TOTAL",

  filterProperty : "P8_TOTAL",

this.getText returns "", so the comparison can't be done.

P.S. I'm using oData for fetching the values.

Any Ideas?

Thank you.

former_member182372
Active Contributor
0 Kudos

hmmm.... for Json it works just fine

JS Bin - Collaborative JavaScript Debugging&lt;/title&gt; &lt;link rel=&quot;alternate&quot; type=&q...

do you see the value from P8_total in the table or it is also blank?

RyabovAlex
Advisor
Advisor
0 Kudos

Hello Maksim,

we colleague found an answer here:

We had pass the cell value.

Thank you anyway!