KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.

PivotMatrix and own Array not working #968

Open al opened this topic on on Jul 4 - 2 comments

al commented on Jul 4

Hi,

all i get is an empty Table. What could be wrong? As a normal Table the values are there, but not in PivotMatrix.

This is the Code:

<?php
error_reporting(E_ALL);



$data = [];
$data[] = ['MANDT','EBELN','BSART','LIFNR','EKORG','EKGRP','WAERS','VERKF','EBELP','TXZ01','MATNR','MATKL','MENGE','MEINS','NETPR','NETWR'];
$data[] = ["800","3000000007","EC","0000003730","3000","011","USD","Mr. Griswald","1","High Speed Printer/Laser Printer","MSA-2000","002","1","ST","2228","2228"];
$data[] = ["800","3000000007","EC","0000003730","3000","011","USD","Mr. Griswald","2","Maxitec R 3200 personal computer","R-1002","002","1","ST","1698","1698"];
$data[] = ["800","3000000007","EC","0000003730","3000","011","USD","Mr. Griswald","3","PAQ Monitor, 21, Color","MSA-2006","002","1","ST","532","532"];
$data[] = ["800","3000000009","EC","0000003411","3000","010","USD","","1","Shafting assembly","WL-1000","001","3","ST","120","360"];
$data[] = ["800","3000000009","EC","0000003411","3000","010","USD","","3","Pressure cover","100-400","001","2","ST","162","324"];


################################################################################################

require_once '/var/www/localhost/htdocs/_custom/third_party/koolreport_pro-4.1.1/koolreport/core/autoload.php';

use \koolreport\KoolReport;
use \koolreport\processes\ColumnMeta;
use \koolreport\processes\Filter;
use \koolreport\processes\Group;
use \koolreport\pivot\processes\Pivot;
use \koolreport\pivot\widgets\PivotMatrix;
use \koolreport\widgets\koolphp\Table;
use \koolreport\widgets\google\PieChart;
use \koolreport\core\Utility;
use \koolreport\instant\Widget;

class MyReport extends KoolReport
{
    public function settings()
    {
        return array(
            "dataSources"=>array(
                "data"=>array(
                    "class"=>'\koolreport\datasources\ArrayDataSource',
                    "data"=>$this->params["data"],
#                    "dataFormat"=>"table",
                )
            )
        );
    }   
    protected function setup()
    {
        $this->src('data')
->pipe(new Pivot(array(
   "dimensions"=>array(
   "column" => "EBELN",
   "row" => "NETWR",
  ),
  "aggregates"=>array(
   "sum"=>"NETWR",
   "count"=>"NETWR"
)
)))
        ->pipe($this->dataStore('data'));
    } 
}






$report = new MyReport(array(
    "data" => $data
));
$report->run()->render();
?>









<div class="report-content">
    <div class="text-center">
        <h1>Interactive Sale Report</h1>
        <p class="lead">Sale Report is built upon interactive PivotMatrix allowing you
            to custom dimension fields or measurement field.
        </p>
    </div>

    <form id='form1' class="form-inline" method="post">

        <?php
        PivotMatrix::create(array(
            "id" => "pivotMatrix1",
            'dataSource' => $report->dataStore('data'),
            "measures"=>array(
                "NETWR",
            ),
            'columnCollapseLevels' => array(0),
            'rowCollapseLevels' => array(0),
            'width' => '100%',
            'totalName' => 'All',
            'waitingFields' => array(
                'NETWR - count' => 'data',
            ),
            'paging' => array(
                'size' => 5000,
                'maxDisplayedPages' => 5,
                'sizeSelect' => array(5, 10, 20, 50, 100)
            )
        ));
        ?>
    </form>
</div>
David Winterburn commented on Jul 5

Hi,

If your datasource is ArrayDataSource you should set its "dataFormat" property to be either "table" or "associate":

"data"=>array(
                    "class"=>'\koolreport\datasources\ArrayDataSource',
                    "data"=>$this->params["data"],
                    "dataFormat" => "table", //default: "associate"
                )

It's "table" if your data's first row is column names and next rows are numeric array. It's "associate" if your data's rows are all associative array. Without the dataFormat property koolreport can't understand your columns' data. Thanks!

al commented on Jul 5

Thanks very much, with dataFormat table it works now!

Give tips to supporter for his good work

If you feel that supporter has done a good work, consider giving him some credit. Any amount put into the tips box below is appreciated. By doing so, you have contribtuted to the existence of KoolReport and the quality of support.

Tips box
solved

None