Hi,
I have a datatable report that I want to be able to export to excel. please note the the datatable includes a merged columns and rows.
This is the code of the report
DataTables::create(array(
"dataSource"=>$this->dataStore("st"),
"options"=>array(
"searching"=>false,
"paging"=>false,
'columnDefs' => array(
array(
'visible' => false,
'targets' => [$this->monthDays+6], //hide the first column
)
),
'rowGroup' => [
//'dataSrc' => [0], //10 is the order of the column you want to group
'endRender' => "function ( rows, group ) {
var totalA = rows
.data()
.pluck($this->monthDays+7)
.reduce( function (a, b) {
return a + b.replace(/[^\d]/g,'')*1;
}, 0);
var totalB = rows
.data()
.pluck($this->monthDays+8)
.reduce( function (a, b) {
return a + b.replace(/[^\d]/g,'')*1;;
}, 0);
var totalTravelCost = rows
.data()
.pluck($this->monthDays+10)
.reduce( function (a, b) {
return a + b*1;
}, 0);
totalTravelCost = $.fn.dataTable.render.number(',', '.', 2).display( totalTravelCost );
return $('<tr/>')
.append( '<td colspan='+($this->monthDays+6)+'>סה״כ שעות מילוי מקום למורה '+group+'</td>' )
.append( '<td class=text-center>'+totalA+'</td>' )
.append( '<td class=text-center>'+totalB+'</td>' )
.append( '<td></td>' )
.append( '<td class=text-center>'+totalTravelCost+'</td>' );
}"
],
),
'complexHeaders' => true,
'headerSeparator' => ' - ',
'cssClass'=>array(
'table'=>'table table-bordered',
'tr'=>'cssItem',
'td'=>function($row,$colName)
{
return in_array($colName, array('substitute_teacher_id','id_number','full_address','bank_account','teacher_id','group_name')) ? 'text-right' : 'text-center';
},
'th'=>function($colName)
{
return in_array($colName, array('substitute_teacher_id','id_number','full_address','bank_account','teacher_id','group_name')) ? 'table-dark text-right' : 'table-dark text-center';
},
),
));
echo '<div class="footer print-only">Footer</div>';
?>