KoolReport's Forum

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

Compare two table column values #2220

Closed Ron opened this topic on 5 days ago - 8 comments

Ron commented 5 days ago

Hi, I have a report that shows a table with three columns Columns 1 = name of person Column 2 = Total dept Column 3 = total paid

I need the following output to display the third column in color: Red in case total paid < total dept Green in case total paid >= total dept I guess I need to use a Map process and scan the value can you please guide me how to do that

Sebastian Morales commented 5 days ago

You can also use Table's "cssClass" property to add css classes for each cell:

https://www.koolreport.com/docs/koolphp/table/#table-settings-cssclass-options

Based on the $row values for your total paid and total debt columns you return certain css classes for your third column. Then add some color css rules in your page for those css classes. Rgds,

KoolReport commented 5 days ago

Another way is to use "formatValue"

Table::create([
    "columns"=>[
        "name",
        "total_dept",
        "total_paid"=>[
            "formatValue"=>function($value,$row) {
                $bgColor = ($row["total_dept"]>$row["total_paid"])?"background-color:red":"background-color:green";
                return "<span style='$bgColor'>$value</span>";
            }
        ]
    ]
]);
Ron commented 5 days ago

Tnx Sebastian. the second way works fine. the issue is that the value is now inside a span and the background color is only in the span itself. I want to mark in red the parent TD of the table that the value is in.

Sebastian Morales commented 5 days ago

Then use the "cssClass" property which would assign css classes to the td element. Rgds,

Ron commented 5 days ago

but can I use the ccClass with a formatValue=>function($value,$row) {}?

KoolReport commented 5 days ago

It is possible, we have example to use the function with "cssClass" that you have a look:

cssClass options

Ron commented 3 days ago

I see the example for the td but I can not access the value inside the td.

Ron commented 3 days ago

problem solved!

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
solved

None