How do I conditionally format a Report's column color based on its data value?

13 views
Skip to first unread message

AppSynergy Support

unread,
Oct 23, 2020, 10:17:17 AM10/23/20
to AppSynergy by ParaSQL Support
For example, if the number in a column is over a certain amount I want it in green, but if it is below a certain amount I want to display it in red. Is that possible?

AppSynergy Support

unread,
Oct 23, 2020, 11:07:24 AM10/23/20
to AppSynergy by ParaSQL Support
Yes! To have full control over how a data cell in a report looks based upon its value, simply add an Event to your Report object (via toolbar > Events...). Be sure the event Type is set to "rendercell" so that it is called each time a data cell is rendered. 

Sample code for a "rendercell" event:

function (event) {

 
// get info about the data cell
 
var dataCell = event.target.getLastRenderedDataCell();

 
// only apply formatting to the Order_Total column
 
if (dataCell.columnName == 'Order_Total') {

   
if (dataCell.dataValue.getNumber() > 1000) {

      dataCell
.dataCellDiv.style.backgroundColor = 'rgba(0,250,0,0.5)';

   
} else if (dataCell.dataValue.getNumber() < 200 && dataCell.dataValue.isNotNull() ) {

      dataCell
.dataCellDiv.style.backgroundColor = 'rgba(250,0,0,0.5)';

   
}
 
}
}

The event.target property always points to the object that fired the event (a ReportWidget in this case). See the Application API documentation for details on the classes and methods available.

The Events panel looks like this:



The resulting report column looks like this:

Reply all
Reply to author
Forward
0 new messages