Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines
This was working in the previous version
'map' => [
'dataCell' => function($value, $cellInfo) {
$columns = [];
$rows = [];
$data = '';
foreach( $cellInfo['row'] as $k=>$v ){
if( is_array( $v ) && $v['value'] != '{{all}}' && $v['value'] != '{{other}}'){
$rows['$k'] = $v;
$y = $v['value'];
$data .= " data-$k='$y' ";
}
}
foreach( $cellInfo['column'] as $k=>$v ){
if( is_array( $v ) && $v['value'] != '{{all}}' && $v['value'] != '{{other}}'){
$columns['$k'] = $v;
$y = $v['value'];
$data .= " data-$k='$y' ";
}
}
return "<a target='_blank' class='run-subreport' $data>$cellInfo[formattedValue]</a>";
},
'rowField' => function($rowField, $fieldInfo) {
return translate( $rowField, '' );
},
'columnField' => function($colField, $fieldInfo) {
return translate( $colField, '' );
},
'dataField' => function($dataField, $fieldInfo) {
return translate( $dataField, '' );
},
'waitingField' => function($waitingField, $fieldInfo) {
return translate( $waitingField, '' );
},
'columnHeader' => function($colHeader, $headerInfo) {
$v = $colHeader;
if ($headerInfo['fieldName'] === 'month')
$v = translate($v, $headerInfo['fieldName']);
return $v;
},
],
KoolReport v4.3.1 This is in the view:
function translate( $v, $f ){
switch ($v) {
case 'sale_amount - sum': return 'Summe';
case 'sale_amount - count': return 'Anzahl';
case 'sale_amount - avg': return 'Durchschnitt';
case 'price - avg': return 'Preis Ø';
case 'quantity_amount - sum': return 'Menge';
case 'factor - sum': return 'Faktor';
case 'detail_id - count': return 'Positionen';
case 'order_id': return 'Id';
case 'order_id - distinctCount': return 'Aufträge';
case 'year': return 'Jahr';
case 'quarter': return 'Quartal';
case 'month': return 'Monat';
case 'day': return 'Tag';
case 'from_location_text': return 'Von Standort';
case 'to_location_text': return 'Nach Standort';
case 'from_city': return 'Von Ort';
case 'to_city': return 'Nach Ort';
case 'article_text': return 'Artikel';
case 'customer_text': return 'Kunde';
case 'employee_text': return 'Mitarbeiter';
case 'duration_hours - sum': return 'Dauer (Std.)';
case 'duration_days - sum': return 'Dauer (Tage)';
}
$r = $v;
if ($f === 'year')
$r = 'Year ' . $v;
$map = array(
'' => '',
'1' => 'Januar',
'2' => 'Februar',
'3' => 'März',
'4' => 'April',
'5' => 'Mai',
'6' => 'Juni',
'7' => 'Juli',
'8' => 'August',
'9' => 'September',
'10' => 'Oktober',
'11' => 'November',
'12' => 'Dezember',
);
if ($f === 'month')
$r = $map[$v];
return $r;
}
PivotMatrix::create(array(
"id" => "pivotMatrix1",
'dataSource' => $this->dataStore('test')->count() ? $this->dataStore('sales') : $this->dataStore('default'),
'scope' => [
'typeId' => isset($this->params['typeId']) ? $this->params['typeId'] : '',
'statusId' => isset($this->params['statusId']) ? $this->params['statusId'] : '',
'startDate' => isset($this->params['startDate']) ? $this->params['startDate'] : '',
'endDate' => isset($this->params['endDate']) ? $this->params['endDate'] : '',
'selectedDate' => isset($this->params['selectedDate']) ? $this->params['selectedDate'] : '',
// 'nodeId' => isset($this->params['nodeId']) ? $this->params['nodeId'] : '',
],
"measures"=>array(
"sale_amount - sum",
"quantity_amount - sum",
),
'columnSort' => array(
'month' => function($a, $b) {
return (int)$a < (int)$b;
},
),
'rowSort' => [
'article_text' => 'asc'
],
// 'rowCollapseLevels' => array(0,1),
// 'columnCollapseLevels' => array(0),
'partialProcessing' => true,
'width' => '100%',
'height' => '1000px',
"showDataHeaders" => true,
'totalName' => 'Gesamt',
// 'headerMap' => array(
// 'sale_amount - sum' => 'Summe',
// 'price - avg' => 'Preis Ø',
// 'quantity_amount - sum'=> 'Menge',
// 'factor - sum'=> 'Faktor',
// 'detail_id - count'=> 'Positionen',
// 'order_id - distinctCount'=> 'Aufträge'
// ),
'headerMap' => function($v,$f){
return translate($v,$f);
},
'map' => [
'dataCell' => function($value, $cellInfo) {
$columns = [];
$rows = [];
$data = '';
foreach( $cellInfo['row'] as $k=>$v ){
if( is_array( $v ) && $v['value'] != '{{all}}' && $v['value'] != '{{other}}'){
$rows['$k'] = $v;
$y = $v['value'];
$data .= " data-$k='$y' ";
}
}
foreach( $cellInfo['column'] as $k=>$v ){
if( is_array( $v ) && $v['value'] != '{{all}}' && $v['value'] != '{{other}}'){
$columns['$k'] = $v;
$y = $v['value'];
$data .= " data-$k='$y' ";
}
}
return "<a target='_blank' class='run-subreport' $data>$cellInfo[formattedValue]</a>";
},
// 'rowField' => function($rowField, $fieldInfo) {
// return translate( $rowField, '' );
// },
// 'columnField' => function($colField, $fieldInfo) {
// return translate( $colField, '' );
// },
// 'dataField' => function($dataField, $fieldInfo) {
// return translate( $dataField, '' );
// },
// 'waitingField' => function($waitingField, $fieldInfo) {
// return translate( $waitingField, '' );
// },
// 'columnHeader' => function($colHeader, $headerInfo) {
// $v = $colHeader;
// if ($headerInfo['fieldName'] === 'month')
// $v = translate($v, $headerInfo['fieldName']);
// return $v;
// },
],
'waitingFields' => array(
'duration_days - sum' => 'data',
'duration_hours - sum' => 'data',
'price - avg' => 'data',
'factor - sum' => 'data',
'detail_id - count' => 'data',
'order_id - distinctCount' => 'data',
'order_id' => 'label',
'quarter' => 'label',
'to_location_text' => 'label',
'from_location_text' => 'label',
'to_city' => 'label',
'from_city' => 'label',
'customer_text' => 'label',
'employee_text' => 'label',
'article_text' => 'label',
'month' => 'label',
),
'paging' => array(
'size' => 1000,
'maxDisplayedPages' => 1000,
// 'sizeSelect' => 10000
'sizeSelect' => array(1000)
)
));
?>
This is my export file:
include "MyReport.php";
$report = new MyReport;
$report->run()->exportToExcel('MyReportExcel')->toBrowser("Auftragspivot.xlsx");
This is the html:
Here is the excel:
Hi David,
indeed I has some missing translations in the excel view. But still, if I use only the map function the agregate column headers do not get translated. Here is an exemple where I only use the map. Do we need to use headerMap and map together?
<?php
function translate( $v, $f ){
switch ($v) {
case 'sale_amount - sum': return 'Summe';
case 'sale_amount - count': return 'Anzahl';
case 'sale_amount - avg': return 'Durchschnitt';
case 'price - avg': return 'Preis Ø';
case 'quantity_amount - sum': return 'Menge';
case 'factor - sum': return 'Faktor';
case 'detail_id - count': return 'Positionen';
case 'order_id': return 'Id';
case 'order_id - distinctCount': return 'Aufträge';
case 'year': return 'Jahr';
case 'quarter': return 'Quartal';
case 'month': return 'Monat';
case 'day': return 'Tag';
case 'from_location_text': return 'Von Standort';
case 'to_location_text': return 'Nach Standort';
case 'from_city': return 'Von Ort';
case 'to_city': return 'Nach Ort';
case 'article_text': return 'Artikel';
case 'customer_text': return 'Kunde';
case 'employee_text': return 'Mitarbeiter';
case 'duration_hours - sum': return 'Dauer (Std.)';
case 'duration_days - sum': return 'Dauer (Tage)';
}
$r = $v;
if ($f === 'year')
$r = 'Year ' . $v;
$map = array(
'' => '',
'1' => 'Januar',
'2' => 'Februar',
'3' => 'März',
'4' => 'April',
'5' => 'Mai',
'6' => 'Juni',
'7' => 'Juli',
'8' => 'August',
'9' => 'September',
'10' => 'Oktober',
'11' => 'November',
'12' => 'Dezember',
);
if ($f === 'month')
$r = $map[$v];
return $r;
}
PivotMatrix::create(array(
"id" => "pivotMatrix1",
'dataSource' => $this->dataStore('test')->count() ? $this->dataStore('sales') : $this->dataStore('default'),
'scope' => [
'typeId' => isset($this->params['typeId']) ? $this->params['typeId'] : '',
'statusId' => isset($this->params['statusId']) ? $this->params['statusId'] : '',
'startDate' => isset($this->params['startDate']) ? $this->params['startDate'] : '',
'endDate' => isset($this->params['endDate']) ? $this->params['endDate'] : '',
'selectedDate' => isset($this->params['selectedDate']) ? $this->params['selectedDate'] : '',
// 'nodeId' => isset($this->params['nodeId']) ? $this->params['nodeId'] : '',
],
"measures"=>array(
"sale_amount - sum",
"quantity_amount - sum",
),
'columnSort' => array(
'month' => function($a, $b) {
return (int)$a < (int)$b;
},
),
'rowSort' => [
'article_text' => 'asc'
],
// 'rowCollapseLevels' => array(0,1),
// 'columnCollapseLevels' => array(0),
'partialProcessing' => true,
'width' => '100%',
'height' => '1000px',
"showDataHeaders" => true,
'totalName' => 'Gesamt',
// 'headerMap' => array(
// 'sale_amount - sum' => 'Summe',
// 'price - avg' => 'Preis Ø',
// 'quantity_amount - sum'=> 'Menge',
// 'factor - sum'=> 'Faktor',
// 'detail_id - count'=> 'Positionen',
// 'order_id - distinctCount'=> 'Aufträge'
// ),
// 'headerMap' => function($v,$f){
// return translate($v,$f);
// },
'map' => [
'dataCell' => function($value, $cellInfo) {
$columns = [];
$rows = [];
$data = '';
foreach( $cellInfo['row'] as $k=>$v ){
if( is_array( $v ) && $v['value'] != '{{all}}' && $v['value'] != '{{other}}'){
$rows['$k'] = $v;
$y = $v['value'];
$data .= " data-$k='$y' ";
}
}
foreach( $cellInfo['column'] as $k=>$v ){
if( is_array( $v ) && $v['value'] != '{{all}}' && $v['value'] != '{{other}}'){
$columns['$k'] = $v;
$y = $v['value'];
$data .= " data-$k='$y' ";
}
}
return "<a target='_blank' class='run-subreport' $data>$cellInfo[formattedValue]</a>";
},
'rowField' => function($rowField, $fieldInfo) {
return translate( $rowField, '' );
},
'columnField' => function($colField, $fieldInfo) {
return translate( $colField, '' );
},
'dataField' => function($dataField, $fieldInfo) {
return translate( $dataField, '' );
},
'waitingField' => function($waitingField, $fieldInfo) {
return translate( $waitingField, '' );
},
'columnHeader' => function($colHeader, $headerInfo) {
if ($headerInfo['fieldName'] === 'month')
{
$v = translate($colHeader, $headerInfo['fieldName']);
}
else
{
$v = translate($colHeader, '');
}
return $v;
},
],
'waitingFields' => array(
'duration_days - sum' => 'data',
'duration_hours - sum' => 'data',
'price - avg' => 'data',
'factor - sum' => 'data',
'detail_id - count' => 'data',
'order_id - distinctCount' => 'data',
'order_id' => 'label',
'quarter' => 'label',
'to_location_text' => 'label',
'from_location_text' => 'label',
'to_city' => 'label',
'from_city' => 'label',
'customer_text' => 'label',
'employee_text' => 'label',
'article_text' => 'label',
'month' => 'label',
),
'paging' => array(
'size' => 1000,
'maxDisplayedPages' => 1000,
// 'sizeSelect' => 10000
'sizeSelect' => array(1000)
)
));
?>
Hi Ralf,
Unfortunately, the data headers could only be mapped with the newer map
property and not with the older headerMap
. An example code is:
'map' => array(
...
'dataHeader' => function($dataField, $fieldInfo) {
$v = $dataField;
return $v . '-data';
},
...
Let us know if this works for you. Thanks!
Let KoolReport help you to make great reports. It's free & open-source released under MIT license.
Download KoolReport View demo