KoolReport's Forum

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

How to customize table to create colored legend #162

Open jackywest opened this topic on on Dec 4, 2017 - 2 comments

jackywest commented on Dec 4, 2017

Hi,

I would like to add colors to my data table to get something like in screenshot to export it in PDF. How can i do it ?

jackywest commented on Dec 4, 2017

I'm searching solutions and i think to format value and add an HTML code to create a square or something. But i can't manage to format columni get an "Undefined index: color" using an arrayDataSource with associate keys.

KoolReport commented on Dec 5, 2017

Hi Jacky,

For the first column, you may use the "formatValue"

<?php 
    Table::create(array(
        ...
        "columns"=>array(
            "amount"=>array(
                'formatValue'=>function($value)
                {
                    return "$ ".$value; //You should return html containing name and colored circle
                }
            ),
        ),
        ...
    ));
?>

For second column, you may use the cssClass like below:

    Table::create(array(
        "cssClass"=>array(
            "td"=>function($row,$columnName)
            {
                if($columnName=="column2") //Replace with your real name of column 2
                {
                    //Base on $row["{column_name}"], you return correct css class to add css class
                    if($row["first_column"]=="water")
                    {
                        return "blueCss";
                    } 
                }
            }
        )
    ));
?>

Now you should have the <style> to define color

<style>
    .blueCss
    {
        background-color;blue;
    }
</style>

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