Dynamic alter colour cell with JavaScript

diogofbp

22-06-2016

Hello Guys,

I'm facing the current problem:

I want change a colour cell depends on the value of the cell variable. I'm using the following JavaScript code on the initialize event of this cell

data.First.MainTable.Table1.Row1.Cell6::initialize - (JavaScript, client)

var numrows = xfa.resolveNodes("data.First.MainTable.Table1.Row1[*]").length;

for (var i = 0; i < numrows; i++)

{

    var LV_DATA = xfa.resolveNode("data.First.MainTable.Table1.Row1[" + i + "].Cell6");

  

    switch(LV_DATA){

       case LV_DATA <= "2":

            this.border.fill.color.value = "0, 153, 0";

            break;

       case LV_DATA >= "3" && LV_DATA <= "6":

            this.border.fill.color.value = "255, 255, 0";

            break;

       case LV_DATA> "6":

            this.border.fill.color.value = "255, 0, 0";

            break;

       default:

            this.border.fill.color.value = "255, 255, 255";

    }

}

Print1.PNG

My output values is:

Print2.PNG

With this output on column RISK Level I should get the first two cells red and the last one yellow.

Can you help me?

Accepted Solutions (0)

Answers (1)

Answers (1)

Karwan_Mawlood

23-06-2016

Hi Diogofbp,

welcome to Adobe.

Please use below code there is some errors in your code, and use the layoutready.

data.First.MainTable.Table1.Row1.Cell6::layoutReady - (JavaScript, client)

var numrows = data.First.MainTable.Table1.Row1.instanceManager.count;

for (var i = 0; i < numrows; i++)

{

    var LV_DATA = xfa.resolveNode("data.First.MainTable.Table1.Row1["  +  i  +  "]").Cell6.rawValue;

    switch(LV_DATA){

      case LV_DATA <= "2":

            this.border.fill.color.value = "0, 153, 0";

            break;

      case LV_DATA >= "3" && LV_DATA <= "6":

            this.border.fill.color.value = "255, 255, 0";

            break;

      case LV_DATA> "6":

            this.border.fill.color.value = "255, 0, 0";

            break;

      default:

            this.border.fill.color.value = "255, 255, 255";

    }

}