KoolReport's Forum

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

Koolreport Dashboard - PDF orientation issue #2711

Open Suvindran opened this topic on on Jun 7, 2022 - 1 comments

Suvindran commented on Jun 7, 2022

Hi, I am using Koolreport Dashboard package on Laravel framework, trying to export the PDF for the PivotTable widget. However, I am unable to set neither the orientation nor the margin of the PDF; the page size format works though. Page orientation has no effect while applying the margin setting straight out jammed the whole system (including other users) when I try to export. Attached below is the table file coding.

<?php
namespace App\Dashboard\FolderName;
use \koolreport\dashboard\widgets\pivot\PivotTable;
use \koolreport\pivot\processes\Pivot;

use \koolreport\dashboard\fields\Currency;
use \koolreport\dashboard\fields\DateTime;
use \koolreport\dashboard\fields\Text;
use \koolreport\dashboard\fields\Number;
use \koolreport\dashboard\fields\Button;
use \koolreport\dashboard\admin\relations\HasMany;
use \koolreport\dashboard\admin\Resource;
use \koolreport\dashboard\fields\Badge;
use \koolreport\dashboard\fields\Date;
use \koolreport\dashboard\fields\ID;
use \koolreport\dashboard\fields\RelationLink;
use \koolreport\dashboard\inputs\Select;

use App\Dashboard\AutoMaker;
use \koolreport\dashboard\containers\Html;

class ClassName extends PivotTable
{
	protected function onCreated()
	{
		$this->pdfExportable([
            "format"=>"A4",
			"orientation"=>"landscape",
            
        ])->xlsxExportable(true);
	}


	protected function onExporting($params)
	{
		return true;
	}

	public function exportedView()
	{
		$range = $this->sibling("DateRange")->value();

		return  Html::div([
			Html::h1("Title from " .$range[0].' to '.$range[1])
		])->class("text-center")->view().
			$this->view();
	}
	
	protected function dataSource()
	{

		$range = $this->sibling("DateRange")->value();

		return AutoMaker::rawsql("the raw sql");
	}
	
		protected function process()
	{
		return [
			'dimensions'=>array(
				'row'=>'HDR1_DESC, HDR2_DESC, HDR3_DESC, Content_Desc'
			),
			'aggregates'=>array(
				'sum'=>'Balance',
			),
		];
	}

	protected function display()
	{
		return [
			'rowSort' => (array(
				"HDR1_DESC"=>function($m1, $m2) {
					
					$map = array(
						//the row data name and sequence
					);
					return $map[$m1] < $map[$m2];
				},
			)),
			'totalName' => 'Total (MYR)',
			'map' => array(
				'dataField' => function($dataField, $fieldInfo) {
					$v = $dataField;
					if ($v === 'Balance - sum')
						$v = 'Title'
					return $v;
				},
				'dataCell' => function($value, $cellInfo) {
					if($cellInfo["fieldName"] === "Balance - sum"){
						$cellInfo["formattedValue"] = number_format($value,2,".",",");

						if($value < 0){
							$cellInfo["formattedValue"] = "(" . number_format(abs($value),2,".",",") .")";
						}
					}
					return $cellInfo["formattedValue"];
				}

			),
			'hideTotalRow' => true,
			
			
		];
	}
}

Any suggestion?

Sebastian Morales commented on Jun 7, 2022

Pls try pdf's settings at the dashboard level, not at widget level:

https://www.koolreport.com/docs/dashboard/export/#dashboard-export-settings

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