PivotTable and PivotMatrix using Bun template

Bun template saves blank spaces when expanding rows in comparison to default template


PivotTable::create(array(
    ...
    'template' => 'PivotTable-Bun',
    ...
));




PivotMatrix::create(array(
    ...
    'template' => 'PivotMatrix-Bun',
    ...
));
 
  dollar_sales - sum   dollar_sales - count   dollar_sales - avg  
  orderYear   orderQuarter  
  customerName   productLine   productName  
2004
2005
Total
Total
Total
Total
AV Stores, Co.
Amica Models & Co.
Anna's Decorations, Ltd
Alpha Cognac
Atelier graphique
$189,950
$64
$2,968
$69,365
$24
$2,890
$259,315
$88
$2,947
$99,984
$35
$2,857
-
-
-
$99,984
$35
$2,857
$82,223
$26
$3,162
-
-
-
$82,223
$26
$3,162
-
-
-
$56,932
$19
$2,996
$56,932
$19
$2,996
-
-
-
$12,432
$5
$2,486
$12,432
$5
$2,486
$7,743
$3
$2,581
-
-
-
$7,743
$3
$2,581
Page size:

This examples show how to use BunTemplate, a custom template for Pivot Table. Bun Template contains custom html layout, css to make Pivot save space when expanding row. This is very useful when your pivot table contains many row levels.

For your information, The Bun Template can be used with both Pivot widget and PivotMatrix widget.

<?php
require_once "MyReport.php";

$report = new MyReport;
$report->run()->render();
<?php
//Step 1: Load KoolReport
require_once "../../../load.koolreport.php";
use \koolreport\pivot\processes\Pivot;
use \koolreport\pivot\processes\PivotExtract;
use \koolreport\processes\ColumnMeta;
use \koolreport\processes\Filter;

//Step 2: Creating Report class
class MyReport extends \koolreport\KoolReport
{
    function settings()
    {
        return array(
            "dataSources" => array(
                "dollarsales"=>array(
                    'filePath' => '../../../databases/customer_product_dollarsales2.csv',
                    'fieldSeparator' => ';',
                    'class' => "\koolreport\datasources\CSVDataSource"      
                ), 
            )
        );
    }

    public function setup()
    {
        $node = $this->src('dollarsales');

        $node->pipe(new Filter(array(
            array('customerName', '<', 'Au'),
            array('orderYear', '>', 2003),
        )))
        ->pipe(new ColumnMeta(array(
            "dollar_sales" => array(
                'type' => 'number',
                "prefix" => "$",
            ),
        )))
        ->saveTo($node2);

        $node2->pipe(new Pivot(array(
            "dimensions" => array(
                // "column" => "orderYear, orderQuarter, orderMonth, orderDay",
                "column" => "orderYear, orderQuarter",
                "row" => "customerName, productLine, productName",
                // "row" => "customerName, productLine",
            ),
            "aggregates" => array(
                "sum" => "dollar_sales",
                "count" => "dollar_sales",
                "avg" => "dollar_sales",
                'sum percent' => 'dollar_sales',
                'count percent' => 'dollar_sales',
            ),
        )))->pipe($this->dataStore('salesTable'));

        $node2->pipe(new Pivot(array(
            "dimensions" => array(
                // "column" => "orderYear, orderQuarter, orderMonth, orderDay",
                "column" => "orderYear, orderQuarter",
                "row" => "customerName, productLine, productName",
                // "row" => "customerName, productLine",
            ),
            "aggregates" => array(
                "sum" => "dollar_sales",
                "count" => "dollar_sales",
                "avg" => "dollar_sales",
                'sum percent' => 'dollar_sales',
                'count percent' => 'dollar_sales',
            ),
            'partialProcessing' => true,
        )))->pipe($this->dataStore('salesMatrix'));
    }
}
<?php
use \koolreport\pivot\widgets\PivotTable;
use \koolreport\pivot\widgets\PivotMatrix;
?>

<div class="report-content">
    <div class="text-center">
        <h1>PivotTable and PivotMatrix using Bun template</h1>
        <p class="lead">
            Bun template saves blank spaces when expanding rows in comparison to default template
        </p>
    </div>

    <pre style="font-weight:bold"><code>
PivotTable::create(array(
    ...
    'template' => 'PivotTable-Bun',
    ...
));</code></pre>
    <i class="fa fa-arrow-down" style="font-size:24px;"></i>
    <div style="margin-top:20px;">
        <?php
            $dataStore = $this->dataStore('salesTable');
            PivotTable::create(array(
                "name" => "PivotTable1",
                'template' => 'PivotTable-Bun',
                "dataStore" => $dataStore,
                "rowDimension" => "row",
                "columnDimension" => "column",
                "measures"=>array(
                    "dollar_sales - sum",
                    'dollar_sales - count',
                    'dollar_sales - avg',
                ),
                'rowSort' => array(
                    'dollar_sales - sum' => 'desc',
                ),
                'columnSort' => array(
                    'orderMonth' => function ($a, $b) {
                        return (int) $a < (int) $b;
                    },
                    // 'dollar_sales - sum' => 'desc',
                    // 'orderYear' => 'desc',
                ),
                'rowCollapseLevels' => array(1),
                'columnCollapseLevels' => array(0),
                'width' => '100%',
            ));
        ?>
    </div>
    <br><br><br>
    <pre style="font-weight:bold"><code>
PivotMatrix::create(array(
    ...
    'template' => 'PivotMatrix-Bun',
    ...
));</code></pre>
    <i class="fa fa-arrow-down" style="font-size:24px;"></i>
    <div style="margin-top:20px;">
    
    <?php
        $dataStore = $this->dataStore('salesMatrix');
        PivotMatrix::create(array(
            "name" => "PivotMatrix1",
            'template' => 'PivotMatrix-Bun',
            "dataStore" => $dataStore,
            "rowDimension" => "row",
            "columnDimension" => "column",
            "measures"=>array(
                "dollar_sales - sum",
                'dollar_sales - count',
                'dollar_sales - avg',
            ),
            'rowSort' => array(
                'dollar_sales - sum' => 'desc',
            ),
            'columnSort' => array(
                'orderMonth' => function ($a, $b) {
                    return (int) $a < (int) $b;
                },
                // 'dollar_sales - sum' => 'desc',
                // 'orderYear' => 'desc',
            ),
            'width' => '100%',
            'paging' => array(
                'size' => 20
            )
        ));
    ?>
    </div>
</div>

customerNameproductNameproductLineorderDateorderDayorderMonthorderYearorderQuarterdollar_sales
Vitachrome Inc. 1937 Lincoln Berline Vintage Cars 2003-01-10 00:00:00 10 1 2003 1 3726.45
Vitachrome Inc. 1936 Mercedes-Benz 500K Special Roadster Vintage Cars 2003-01-10 00:00:00 10 1 2003 1 1768.33
Baane Mini Imports 1952 Alpine Renault 1300 Classic Cars 2003-01-29 00:00:00 29 1 2003 1 5571.8
Baane Mini Imports 1962 LanciaA Delta 16V Classic Cars 2003-01-29 00:00:00 29 1 2003 1 5026.14
Baane Mini Imports 1958 Setra Bus Trucks and Buses 2003-01-29 00:00:00 29 1 2003 1 3284.28
Baane Mini Imports 1940 Ford Pickup Truck Trucks and Buses 2003-01-29 00:00:00 29 1 2003 1 3307.5
Baane Mini Imports 1926 Ford Fire Engine Trucks and Buses 2003-01-29 00:00:00 29 1 2003 1 1283.48
Baane Mini Imports 1913 Ford Model T Speedster Vintage Cars 2003-01-29 00:00:00 29 1 2003 1 2489.13
Baane Mini Imports 1934 Ford V8 Coupe Vintage Cars 2003-01-29 00:00:00 29 1 2003 1 2164.4
Baane Mini Imports 18th Century Vintage Horse Carriage Vintage Cars 2003-01-29 00:00:00 29 1 2003 1 2173

What People Are Saying

"KoolReport helps me very much in creating data report for my corporate! Keep up your good work!"
-- Alain Melsens

"The first use of your product. I was impressed by its easiness and powerfulness. This product is a great and amazing."
-- Dr. Lew Choy Onn

"Fantastic framework for reporting!"
-- Greg Schneider

Download KoolReport Get KoolReport Pro