How to change a report cell format based on its value
Change cell format based on value
Sometimes you might want to change the display format of a value in a report based on its contents or data. For example, in the realtime queue summary report, you might want to show abandoned calls in bold/red when they reach certain limit.
This can be achieved via report designer and a little bit of programming.
Report Designer
You can define a format via report designer with the value being a php function call, something like this:
keyword: COLUMN_REALTIME_FORMAT parameter: Abandoned value: show_alarm_abandon
This will apply the format function defined on the value field to the field 'Abandoned' (specified in the parameter field), for columns on the realtime view for the queue summary display. So, the next step is to create the "show_alarm_abandon" function:
Display Function
You must create the "show_alarm_abandon" function for php. The place to do it is the custom.php file in the main directory.
You will see that there are already a couple of sample functions there, you can investigate them if you want. For this example, we will create a new function that will display the value in red if its higher or equal to 10, in yellow if is higher or equal to 5, or with no special format otherwise. Here is the function code:
function show_alarm_abandon($value) { $returnvalue = Array(); if($value>=10) { $returnvalue[] = "<span style='color: #F00; font-weight: bold'>$value</span>"; } else if($value>=5) { $returnvalue[] = "<span style='color: #FF0; font-weight: bold'>$value</span>"; } else { $returnvalue[] = "$value"; } $returnvalue[] = $value; return $returnvalue; }
Notice that the format function returns an array, containing two values. The first one is the formatted value, the 2nd one is unformmated (for JSON or CSV exports).