Print, Export CSV, Excel, Pdf return blank page
Print, Export CSV, Excel, Pdf return blank page
RaudhohFitra_h
Posts: 1Questions: 1Answers: 0
I am using codeigniter. And take header and data dynamically from database.
But, I have no idea why this print, and export returns blank page.
Here is my controller
$cols = $this->pdrb->select_cols($this->data['modul']);
$results = $this->pdrb->select_all_lapus();
$data = array();
$header = array();
$header[] ="Indikator";
for($i = 0 ; $i <count($cols); $i++)
{
$row = $cols[$i]['col_name'];
for($j=0; $j < count($results); $j++)
{
if($i == 0)
{
$header[] = $results[$j]['plapus_year'];
}
if($j < count($results))
{
$row .="|";
}
$row .= $results[$j][$cols[$i]['col_code']];
}
$data[] = $row;
}
$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->general->count_all(), "data" => $data,
"columns" =>$header,
);
//output to json format
echo json_encode($output);`
And here's the jquery
var table;
$(document).ready(function() {
//datatables
table = $('#table').DataTable({
"serverSide": true, //Feature control DataTables' server-side processing mode.
"order": [], //Initial no order.
// Load data for the table's content from an Ajax source
"ajax": {
"url": "<?php echo site_url('pdrb_lapus/master_ajax_list')?>",
"type": "POST",
"success":function(json)
{
var headers;
headers ="<table id='table' border='1' cellpadding='2' cellspacing='1' class='display'><thead><tr>";
$.each(json.columns, function(i, val){
headers += "<th>" + val + "</th>";
});
headers +="</tr></thead><tbody>";
$.each(json.data, function(i, cols){
headers +="<tr>" ;
var col = cols.split("|");
var c = col.length;
var atarget = [];
var stitle =[];
for(var u=0;u<c;u++)
{
atarget[u] = u;
stitle[u] = col[u];
headers +="<td>"+col[u]+"</td>";
}
headers +="</tr>";
});
headers +="</tbody></table>";
$('#table').append(headers);
},
},
//Set column definition initialisation properties.
"columnDefs": [
{
"targets": [ 0 ], //first column / numbering column
"orderable": true, //set not orderable
},
],
"dom": 'lBfrtip',
"buttons": [
'copy', 'csv', 'excel', 'pdf', 'print'
],
"bPaginate":false,
"bInfo":false,
});
$("#table_filter").css("display","none");
$('.search-input-select').on('change',function() { // for select box
if (!!this.value){
table.column(5).search(this.value).draw();
}
else
{
table.column(5).search(this.value).draw();
}
});
});`
I have no more idea what to do. Please help
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This discussion has been closed.
Answers
Post a link to the page showing the issue please . The code shown above looks okay as far as I can see. I would need a test page showing the issue to be able to debug it and offer any help.
Allan
Btw: If you are using server-side processing (which you are - although your PHP code doesn't really appear to account for it) I would suggest you read the last FAQ in the server-side processing FAQs.
Unless you are using tens of thousands or more of rows, I would suggest you remove the
serverSide
option.Allan