KoolReport's Forum

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

Report Footers in Laravel / Blade #3121

Open chris rogers opened this topic on on Aug 14, 2023 - 1 comments

chris rogers commented on Aug 14, 2023

I am trying to get the sum() to work in my report footers, where the column value for each row is displayed on conditions.
`

        if(classers.subject LIKE "%Math%",it.total_amount,"") AS Math, 
        if(classers.subject LIKE "%Science%",it.total_amount,"") AS Science, 
        if(classers.subject LIKE "%Robot%",it.total_amount,"") AS Robotics

I have extracted the updated code from my previous question where I listed the full code [controller + blade]. [](https://www.koolreport.com/forum/topics/3120) 

{!! Table::create([
    "dataSource" => $data,
    "showFooter" => true,
    "cssClass" => [
        "table" => "table table-striped table-bordered ",
        "tr" => "small-font",
    ],
]) !!}

Also, I found this thread [](https://www.koolreport.com/forum/topics/1887)

where they are using "columns".  I am trying to understand the implementation of this. 
- I am assuming "taxyear", "employee_email", etc. are columns from the table.  Is this correct?
- In my case I have joined a number of tables together and stored the results into the variable $data.  Assuming, I am correct above, how do I reference the different columns eg. table_name.table_column.  This doesn't sound correct given the knowledge of the joins would be unknown.
- Can I specify the column number in $data?

Thanks again

Chris

"columns"=>array(

    "taxyear",
    "employee_email",
    "employee_title",
    "cost_center_name",
    "w2_wages"=>array(
        "cssStyle"=>"text-align:left",
        "prefix"=>"$",
        "footer"=>"sum",
        "footerText"=>"<b>Total Wages:</b> @value"
    ),
    "consultant"=>array(
        "formatValue"=>function($value) {
            return ($value==1)?"Yes":"No";
        }
    ),
    "qualified_dollars"=>array(
        "cssStyle"=>"text-align:right",
        "prefix"=>"$",
        "footer"=>"sum",
        "footerText"=>"<b>Total Wages Qualified:</b> @value"
    )
),

Sebastian Morales commented on Aug 18, 2023

In your case, you can set Table's columns' footer as a function like this:

https://www.koolreport.com/docs/koolphp/table/#table-settings-aggregated-footer

    Table::create(array(
        ...
        "showFooter"=>"bottom",
        "columns"=>array(
            "amount"=>array(
                "footer"=>function($datastore)
                {
                    return "$".number_format($datastore->sum("amount"));
                },
                "footerText"=>"Amount: @value",
            ),
        ),
        ...
    ));

If there's any difficulty let us know.

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
help needed

Laravel