KoolReport's Forum

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

PivotTable in Dashboard - Scroll horizontally & Total Labels #3183

Open John opened this topic on on Oct 28, 2023 - 9 comments

John commented on Oct 28, 2023

At my PivotTable (in Dashboard) i have many columns/data, so I tried unsuccesfully to replicate the horizontally scroll which i see in this example: https://www.koolreport.com/examples/reports/pivot/aggregates_computations/ by using this line of code: 'cssClass' => array('pivot-table' => "overflow: scroll",),

I also tried to change names to Total labels (please see the image below) but i couldn't find a solution, can you help?

I know that i can change name to Total label for all Totals like this: 'totalName' => 'All' but this is not enough as you can see at image above.

Sebastian Morales commented on Oct 30, 2023

With PivotTable you only need to set its parent div's width to a fixed width and overflow: auto or overflow: scroll like this:

<div style="width: 1024px; overflow: auto;">
    <?php PivotTable::create(...); ?>
</div>

With Total name you could use a callback function like this:

PivotTable::create(array(
    ...
    "totalName" => function($value, $info) {
        print_r($info);
        //customize total name of each level according to $value and/or $info
        $totalName = ...;
        return $totalName;
    }            
));
John commented on Oct 30, 2023

Thanks but in Dashboard i can't add any style to my php file like this... It always shows an Error (i mentioned this in another ticket also).

John commented on Oct 30, 2023

Ok i finally managed to make it scroll via my custom css file.

John commented on Oct 30, 2023

But custom css file may not be a good solution as it affects other widgets and make them look ugly... i found a css selector for the time beeing...

Sebastian Morales commented on Oct 31, 2023

In Dashboard you can add in-page style for each board like this to avoid using the global css files:

    protected function content()
    {
        return [
            \koolreport\dashboard\containers\Html::style("
                .pivot-parent-div {
                    width: 1024px; 
                    overflow: auto;
                }
            ")->raw(true),
            ...
        ];
    }
John commented on Nov 4, 2023

The callback function for total name you proposed does not work for my purpose.

Sebastian Morales commented on Nov 6, 2023

In the total name's call back function, variable $info is different for each header level. Based on that you can return different total names. If there's any problem let us know the detail.

John commented on Nov 6, 2023

I have set this code:

if ($info['fieldName'] === 'YearlyQry')
    $totalName = 'Year Total';
return $totalName;

but it shows me error.

My print_r($info) gives me this:

Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( [childOrder] => 1.2 [value] => {{all}} [total] => 1 [numChildren] => 1 [numLeaf] => 1 [level] => 1 [fieldName] => Subcategory [fieldOrder] => 1 [row] => Array ( [Category] => Array ( [value] => Income for services ) [Subcategory] => Array ( [childOrder] => 1.2 [value] => {{all}} [total] => 1 [numChildren] => 1 [numLeaf] => 1 [level] => 1 ) [hasTotal] => 1 [fieldOrder] => 0 ) ) Array ( [childOrder] => 2.2 [value] => {{all}} [total] => 1 [numChildren] => 1 [numLeaf] => 1 [level] => 1 [fieldName] => Subcategory [fieldOrder] => 1 [row] => Array ( [Category] => Array ( [value] => Other ) [Subcategory] => Array ( [childOrder] => 2.2 [value] => {{all}} [total] => 1 [numChildren] => 1 [numLeaf] => 1 [level] => 1 ) [hasTotal] => 1 [fieldOrder] => 0 ) ) Array ( [childOrder] => 3 [value] => {{all}} [total] => 1 [numChildren] => 1 [numLeaf] => 1 [level] => 2 [fieldName] => Category [fieldOrder] => 0 [row] => Array ( [Category] => Array ( [childOrder] => 3 [value] => {{all}} [total] => 1 [numChildren] => 1 [numLeaf] => 1 [level] => 2 ) [Subcategory] => Array ( [childOrder] => 0.1 [value] => {{all}} [total] => 1 ) [hasTotal] => 1 [fieldOrder] => -1 ) ) Array ( [childOrder] => 0.1 [value] => {{all}} [total] => 1 [fieldName] => Subcategory [fieldOrder] => 1 [row] => Array ( [Category] => Array ( [childOrder] => 3 [value] => {{all}} [total] => 1 [numChildren] => 1 [numLeaf] => 1 [level] => 2 ) [Subcategory] => Array ( [childOrder] => 0.1 [value] => {{all}} [total] => 1 ) [hasTotal] => 1 [fieldOrder] => -1 ) ) Array ( [childOrder] => 1 [value] => {{all}} [total] => 1 [numChildren] => 3 [numLeaf] => 3 [level] => 2 [fieldName] => YearlyQry [fieldOrder] => 0 [column] => Array ( [YearlyQry] => Array ( [childOrder] => 1 [value] => {{all}} [total] => 1 [numChildren] => 3 [numLeaf] => 3 [level] => 2 ) [Period] => Array ( [childOrder] => 0.1 [value] => {{all}} [total] => 1 ) [hasTotal] => 1 [fieldOrder] => -1 ) ) Array ( [childOrder] => 0.1 [value] => {{all}} [total] => 1 [fieldName] => Period [fieldOrder] => 1 [column] => Array ( [YearlyQry] => Array ( [childOrder] => 1 [value] => {{all}} [total] => 1 [numChildren] => 3 [numLeaf] => 3 [level] => 2 ) [Period] => Array ( [childOrder] => 0.1 [value] => {{all}} [total] => 1 ) [hasTotal] => 1 [fieldOrder] => -1 ) ) Array ( [childOrder] => 0.1 [value] => {{all}} [total] => 1 [fieldName] => Period [fieldOrder] => 1 [column] => Array ( [YearlyQry] => Array ( [value] => {{other}} [total] => 1 [numChildren] => 3 [numLeaf] => 3 [level] => 2 [childOrder] => 1 ) [Period] => Array ( [childOrder] => 0.1 [value] => {{all}} [total] => 1 ) [hasTotal] => 1 [fieldOrder] => -1 ) ) Array ( [childOrder] => 1.4 [value] => {{all}} [total] => 1 [numChildren] => 3 [numLeaf] => 3 [level] => 1 [fieldName] => Period [fieldOrder] => 1 [column] => Array ( [YearlyQry] => Array ( [value] => 2023 ) [Period] => Array ( [childOrder] => 1.4 [value] => {{all}} [total] => 1 [numChildren] => 3 [numLeaf] => 3 [level] => 1 ) [hasTotal] => 1 [fieldOrder] => 0 ) )
Sebastian Morales commented on Nov 7, 2023

What is the error? Pls post your total name function code and screenshots of the resulted PivotTable.

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

Dashboard