KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

CssStyle on calculatedcolum #3264

Open Adolfo Alonso opened this topic on on Mar 13 - 1 comments

Adolfo Alonso commented on Mar 13

Hello, im using the following cssStyle to change the backgroud when the calculated column value is smaller than 80.

...
'cssStyle'=>array(
'td' => function($row, $colName) {
if($colName === 'acumulado%' && $row['acumulado%'] < 80) {return 'background-color: #FFCCCB';}
},
),
...

But im also getting the value 100 colored...

Any ideas?

Sebastian Morales commented on Mar 14

I think it's because the column is of string type with string values (i.e "100%", not 100). One method is to replace "%" character and convert the value to number before comparison like this:

if($colName === 'acumulado%') {
    $numericValue = (float) str_replace("%", "", $row['acumulado%']);
    if($numericValue < 80) return 'background-color: #FFCCCB';
}

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

None