KoolReport's Forum

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

How to get the $fieldInfo in php pivot table? #2498

Closed Finu opened this topic on on Dec 16, 2021 - 7 comments

Finu commented on Dec 16, 2021

Hi guys,

I am trying to get the $fieldInfo data in 'map' -> 'dataHeader' so that the data is like $fieldInfo in 'map' -> 'dataCell'.

How to get the $fieldInfo data in 'map' -> 'dataHeader' so that the data is like $fieldInfo in 'map' -> 'dataCell'? Or can pass the $fieldInfo data from 'dataCell' to $fieldInfo 'dataHeader'?

"map" => array(
    "dataCell" => function ($dataField, $fieldInfo) { //from here $fieldInfo
    },

    "dataHeader" => function($dataField, $fieldInfo) { //to here $fieldInfo
    },
    
    "dataField" => function($dataField, $fieldInfo) {
    }
),

How to get the $fieldInfo data in 'map' -> 'dataHeader' so that the data is like $fieldInfo in 'map' -> 'dataCell'? Or can pass the $fieldInfo data from 'dataCell' to $fieldInfo 'dataHeader'?

Please help,

Thank you for your time.

Finu commented on Dec 16, 2021

I want to fetch a value from $fieldInfo data like this

"map" => array(
    "dataCell" => function ($dataField, $fieldInfo) { //from here $fieldInfo
            $fieldInfo['row']['Order_Name']['value'] //this in "dataCell" and managed to get the data
    },

    "dataHeader" => function($dataField, $fieldInfo) { //to here $fieldInfo
            $fieldInfo['row']['Order_Name']['value'] //this in "dataHeader" but can't get the data
    },
    
    "dataField" => function($dataField, $fieldInfo) {
    }
),

How do I get the data on $fieldInfo "dataHeader"?

Finu commented on Dec 16, 2021

Hi guys, please help me

Finu commented on Dec 17, 2021

up

Sebastian Morales commented on Dec 17, 2021

Would you pls post your Pivot process and PivotTable/PivotMatrix create code? Tks,

Finu commented on Dec 17, 2021

Oke,

This is in the Getdata.php file.

<?php
    include(FCPATH . 'assets/kool-report/koolreport/core/autoload.php');
    use \koolreport\pivot\processes\Pivot;
    use \koolreport\pivot\processes\PivotExtract;
    use \koolreport\processes\ColumnMeta;
    use \koolreport\processes\Filter;
    use \koolreport\pivot\PivotExcelExport;
    use \koolreport\processes\RemoveColumn;

    class Getdata extends koolreport\KoolReport {
        private $data;
        private $url;
        public $kot;

        use \koolreport\excel\ExcelExportable;
        use \koolreport\export\Exportable;
        use \koolreport\inputs\Bindable;
        use \koolreport\inputs\POSTBinding;
        

        function __construct($datas = array(), $kot = array()) {
            $this->data = $datas;
            $this->kot = $kot;
            parent::__construct();
        }

        function settings()
        {
            return array(
                "dataSources" => array(
                    "apiarray"=>array(
                        "class"=>'\koolreport\datasources\ArrayDataSource',
                        "dataFormat"=>"associate",        
                    )
                )
            );
        }
    

        function setup()
        {   
            $node = $this->src('apiarray')->load($this->data);
            $node->pipe(new ColumnMeta(array(
                'total'=>array(
                    'type' => 'number'
                ),
            )))
            
            ->pipe(new Pivot(array(
                'dimensions'=>array(
                    'column' => 'Kotama_Nama',
                    'row' => 'Pangkat_Tipe, Golongan_Nama, Pangkat_Nama'
                ),
                'aggregates'=>array(
                    'sum' => 'DSP_O, Riil_O, Perc_O, DSP_N, Riil_N, Perc_N, DSP_Total, Riil_Total, Perc_Total'
                )
            )))
            ->pipe($this->dataStore('Rekap'));
        }
    }

?>

and this is in the getdata.view.php file.

<?php
    use \koolreport\pivot\widgets\PivotTable;
    use \koolreport\pivot\widgets\PivotMatrix;
    use \koolreport\inputs\DateRangePicker;
    use \koolreport\widgets\koolphp\Table;
    $url = $_SESSION['BaseUrl'];
?>

<style>
	.pivot-data-field-content,
	.pivot-data-field-zone,
	.pivot-row-header-text,            
	.pivot-column-header-text,
	{
		visibility: hidden;
	}

	.pivot-data-cell-row-total, 
	.pivot-row-header-grand-total, .pivot-data-cell-row-grand-total {
		font-weight: bold;
		color: #000;
		background-color: #ccc;
	}
</style>

<?php
    $dataStore = $this->dataStore('Rekap');
    PivotTable::create(array(
        'dataStore'=>$dataStore,
        'rowDimension'=>'row',
        'showDataHeaders' => true,
        'columnDimension'=>'column',

        'measures'=>array( 
            ($orgtipe == "O") ? 'DSP_O - sum' : 'DSP_N - sum',
            ($orgtipe == "O") ? 'Riil_O - sum' : 'Riil_N - sum', 
            ($orgtipe == "O") ? 'Perc_O - sum' : 'Perc_N - sum',				
        ),

        'rowSort' => array(
            'Golongan_Nama' => function($a, $b) use($gol) {
                return $gol[$a] <= $gol[$b];
            },
            'Pangkat_Nama' => function($a, $b) use($pang) {
                return $pang[$a] <= $pang[$b];
            },
        ),

        'rowCollapseLevels' => array(1),
        'totalName' => 'TOTAL',
        'width' => '100%',
        'hideSubtotalColumn' => true,
        'hideSubtotalRow' => true,

        'map' => array(
            'dataCell' => function ($dataField, $fieldInfo) {
                if ($fieldInfo['fieldName'] == 'Riil_O - sum') {
                    $kotamaId = $this->kot;
                    $Kotama_Nama = $kotamaId[$fieldInfo['column']['Kotama_Nama']['value']];

                    if ($Pangkat_Nama != "{{all}}") {
                        if ($dataField > 0) {
                            $link  = '<button type="button" class="btn btn-link-primary" onclick="pangkat_nama(`'.$Kotama_Nama.'`)">'.$dataField.'</button>';
                        } else {
                            $link = "0";
                        }
                    } else {
                        if ($dataField > 0) {
                            $link  = "$dataField";
                        } else {
                            $link = "0";
                        }
                    }
                } else {
                    if ($dataField > 0) {
                        $link  = "$dataField";
                    } else {
                        $link = "0";
                    }
                }
                
                return $link;
            },

            'dataHeader' => function($dataField, $fieldInfo) {
                $kotamaId = $this->kot;
                $Kotama_Id = $kotamaId[$fieldInfo['column']['Kotama_Nama']['value']];
                $v = $dataField;
                if($this->orgtipe == "O") {
                    if ($v == 'DSP_O - sum'){
                        $v = 'DSP';
                    }elseif ($v == 'Riil_O - sum') {
                        $v = '<button type="button" class="btn btn-link-primary" onclick="satuan_kerja(`'.$Kotama_Id.'`)">Riil</buttton>';
                    }elseif ($v == 'Perc_O - sum') {
                        $v = '%';
                    }else{
                        $v = 'JUMLAH';
                    }
                } else {
                    if ($v == 'DSP_N - sum'){
                        $v = 'DSP';
                    }elseif ($v == 'Riil_N - sum') {
                        $v = '<button type="button" class="btn btn-link-primary" onclick="satuan_kerja(`'.$Kotama_Id.'`)">Riil</buttton>';
                    }elseif ($v == 'Perc_N - sum') {
                        $v = '%';
                    }else{
                        $v = 'JUMLAH';
                    }
                }
                return $v;
            },
        ),
    ));
?>
</div>
</div>

In the getdata.view.php file in the map->dataCell section I managed to get data from $fieldInfo['column']['Kotama_Nama']['value'], but why in the map->dataHeader section I not get data from $fieldInfo ['column']['Kotama_Nama']['value']. Do you have a solution? Thank you for your time.

Finu commented on Dec 20, 2021

Hi guys, please help me

Sebastian Morales commented on Dec 20, 2021

We are looking into this and trying to improve the field and header info arguments. Pls wait for a few days. We will see if we can come up with a solution. Rgds,

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

Pivot