Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Change Table cell color based on calculated value

Avatar

Level 1

I am trying to change a cell in a tables color based on the value calculated into that field.  Right now I have the cell running a totals column.

Example:  if value is less than 170 turn cell green

                if value is greater than 170 turn cell Red.

Any assistance would be GREATLY appreciated.  Thanks again.

2 Replies

Avatar

Level 1

example:

I have a cell that has the column total in it called "TOTALALLO"  If the total is greater than the value in the "ALLOTEDOCIE" cell then I want the cell to turn red, and if it is less than I want it to trun green.

Thanks again all

SSG_Slair

Avatar

Level 10

Hi,


You could put similar javascript in the exit event of TOTALALLO field:

var vName = this.somExpression;

var fieldObj = xfa.resolveNode(vName + ".ui.#numericEdit.border.fill.color");

if (this.rawValue > ALLOTEDOCIE.rawValue) {

     fieldObj.value = "255,225,225";

}

else {

     fieldObj.value = "225,255,225";

}

/* Check the type of object and change the .ui reference:

     Date field =      #dateTimeEdit 

     Dropdown =      #choiceList 

     Checkbox =      #checkButton 

     Text field =      #textEdit 

     Numeric field =     #numericEdit

*/

Note this is based on TOTALALLO being a numeric field. If it is a text field then you will need to change the ui reference to "textEdit".

Also you will need to apply a solid colour to the field (at design stage) If the field does not have a background fill then you cannot change it with script. To apply a background colour; select the field and go to the Object / Field tab. Select custom in the Appearance drop down and then in the window select solid for the fill. You can select white for the background fill colour.

Lastly the script above just looks at the values and turns the field red or green. You may wish to extend the script to change the background back to white if the field is null.

Good luck,

Niall