KoolReport's Forum

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

Pivot report: how to have pivot column headers and bold face of Total row #2950

Open AhmedHaroon opened this topic on on Jan 18, 2023 - 11 comments

AhmedHaroon commented on Jan 18, 2023

in continuation of my previous post for the Pivot report, i want to Bold the entire Total row and column headers, if possible please guide. below is screenshot for reference. 1 is to have column headers (red colored rectangler) and 2 is for highlight with boldface.

regards

EDIT: i added 'showDataHeaders' => true, in PivotTable::create(array( and it is showing " id - count ridCharges - sum gvm - sum " which is not meaningful for users and management, how i can use custom header and bold Total row?

AhmedHaroon commented on Jan 18, 2023

tried this but still failed, please check my code and screenshot

$dataStore = $this->dataStore('customersData');
                    PivotTable::create(array(
                        "name" => "PivotTable1",
                        'template' => 'PivotTable-Bun',
                        "dataStore" => $dataStore,
                        "rowDimension" => "row",
                        "columnDimension" => "column",
                        "measures"=>array(
                            "id - count",
                            "ridCharges - sum",
                            "gvm - sum",
                        ),
                        "map" => array(
                            'dataField' => function($dataField, $fieldInfo) {
                                $v = $dataField;
                                if ($v === 'id - count')
                                    $v = 'Orders';
                                else if ($v === 'ridCharges - sum')
                                    $v = 'DC';
                                else if ($v === 'gvm - sum')
                                    $v = 'GVM';
                                return $v;
                            },
                            'dataHeader' => function($dataField, $fieldInfo) {
                                $v = $dataField;
                                return $v;
                            },
                        ),
                        "showDataHeaders" => true,
                        
                        'rowSort' => array(
                            'order_date' => 'desc',
                        ),
                        'columnSort' => array(
                            'orderMonth' => function ($a, $b) {
                                return (int) $a < (int) $b;
                            },
                        ),
                        'rowCollapseLevels' => array(1),
                        'columnCollapseLevels' => array(0),
                        'width' => '100%',
                    ));

regards

Sebastian Morales commented on Jan 27, 2023

Sorry for the delayed reply. We have had Lunar New Year for the past week.

Regarding your question, this can be done with CSS. Pls right mouse click the cell, row, or DOM element you want to customize and choose Inspect element to see its css classes. Then add css rules for such classes in your report view. For example:

//MyReport.view.php
<style>
    .pivot-data-header {
        font-weight: bold;
    }
</style>
AhmedHaroon commented on Jan 27, 2023

Happy Lunar New Year

thanks @Sebastian Morales for reply and guidance, will check this as you instructed.

what about column heards? i do not want " - sum " or " - count " etc. etc.

1) " id - count " ... i want -> " Orders "

2) " ridCharges - sum " ... i want -> " DC " ( DC -> Delivery Charges )

3) " gvm - sum " ... i want -> " GVM "

please check in my screenshot, in red oval shape it is showing custom column headers there but not at its actual place mentioned with red rectangle. here these column headers are more meaningful for user/management.

regards

Sebastian Morales commented on Jan 30, 2023

For changing data header text pls try the map's dataHeader subproperty:

PivotTable's map property

AhmedHaroon commented on Jan 31, 2023

@Sebastian Morales thanks for this but i already have tested (also mentioned in my previous post you can see it) and still failed, this has changed only the names appear in my screenshot below, on the left side of 2022, may be i did something wrong, please have a look at code below and guide.

<?php
    if($this->dataStore("customersData")->countData()>0)
    {
                    $dataStore = $this->dataStore('customersData');
                    PivotMatrix::create(array(
                        "name" => "PivotMatrix1",
                        'template' => 'PivotMatrix-Bun',
                        "dataStore" => $dataStore,
                        "rowDimension" => "row",
                        "columnDimension" => "column",
                        "measures"=>array(
                            "id - count",
                            "dc - sum",
                            "gvm - sum",
                        ),
                        "map" => array(
                            'dataField' => function($dataField, $fieldInfo) {
                                $v = $dataField;
                                if ($v === 'id - count')
                                    $v = 'Orders';
                                else if ($v === 'dc - sum')
                                    $v = 'DC';
                                else if ($v === 'gvm - sum')
                                    $v = 'GVM';
                                return $v;
                            },
                            'dataHeader' => function($dataField, $fieldInfo) {
                                $v = $dataField;
                                return $v;
                            },
                        ),
                        "showDataHeaders" => true,
                        
                        'rowSort' => array(
                            'customer_name' => 'asc',
                        ),
                        'columnSort' => array(
                            'MonthYear' => function ($a, $b) {
                                return (int) $a < (int) $b;
                            },
                        ),
                        'rowCollapseLevels' => array(1),
                        'columnCollapseLevels' => array(0),
                        'width' => '100%',
                    ));
    }
    else 
    {
        ?>
            <div class="alert alert-warning">
                <i class="glyphicon glyphicon-info-sign"></i> Sorry, we found no orders.
            </div>
        <?php    
    }
    ?>

Screenshot:

regards

Sebastian Morales commented on Jan 31, 2023

Your "dataHeader" map returns the same input value. Thus, the headers don't change:

                        "map" => array(
                            'dataField' => function($dataField, $fieldInfo) {
                                $v = $dataField;
                                if ($v === 'id - count')
                                    $v = 'Orders';
                                else if ($v === 'dc - sum')
                                    $v = 'DC';
                                else if ($v === 'gvm - sum')
                                    $v = 'GVM';
                                return $v;
                            },
                            'dataHeader' => function($dataField, $fieldInfo) {
                                $v = $dataField;
                                return $v; // you return the same input
                            },
                        ), 
AhmedHaroon commented on Jan 31, 2023

@Sebastian Morales thanks for your passions to guide us.

so, how i can get Headers what i want instead of " id - count " etc.

regards

AhmedHaroon commented on Feb 1, 2023

i modified my code as below, and it worked fine in PivotTable as shown in screenshot below my code, but using same map function in PivotMatrix it is not working, Header is blank instead, what i should do for this?

RiderSummary.view.php

                "map" => array(
                            'dataField' => function($dataField, $fieldInfo) {
                                $v = $dataField;
                                if ($v === 'id - count')
                                    $v = 'Orders';
                                else if ($v === 'ridCharges - sum')
                                    $v = 'DC';
                                else if ($v === 'gvm - sum')
                                    $v = 'GVM';
                                return $v;
                            },
                            'dataHeader' => function($dataField, $fieldInfo) {
                                $v = $dataField;
                                if ($v === 'id - count')
                                    $v = 'Orders';
                                else if ($v === 'ridCharges - sum')
                                    $v = 'DC';
                                else if ($v === 'gvm - sum')
                                    $v = 'GVM';
                                return $v;
                            },

screenshot ( PivotTable - working fine as expected ):

screenshot ( PivotMatrix - failed after added code as above for dataHeader )

please help. regards

AhmedHaroon commented on Feb 1, 2023

it works fine now, it was my mistake, i placed 2 times the map function code. now it have meaningful pivot column headers. thanks @Sebastian Morales for help and guides.

kind regards

.

Sebastian Morales commented on Feb 1, 2023

Welcome, Ahmed.

BennettRachel commented on Feb 2, 2023

interesting information

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
solved

None